mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
27 lines
580 B
Go
27 lines
580 B
Go
package jsonutils
|
|
|
|
import jsoniter "github.com/json-iterator/go"
|
|
|
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
|
|
|
// DocumentToUntyped converts a typed object to JSON data
|
|
// i.e. string, []interface{}, map[string]interface{}
|
|
func DocumentToUntyped(doc interface{}) (interface{}, error) {
|
|
switch doc.(type) {
|
|
case string, []any, map[string]any:
|
|
return doc, nil
|
|
}
|
|
|
|
jsonDoc, err := json.Marshal(doc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var untyped interface{}
|
|
err = json.Unmarshal(jsonDoc, &untyped)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return untyped, nil
|
|
}
|