MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / MakeJSON

Function MakeJSON

pkg/util/json/json.go:975–1003  ·  view source on GitHub ↗

MakeJSON returns a JSON value given a Go-style representation of JSON. * JSON null is Go `nil`, * JSON true is Go `true`, * JSON false is Go `false`, * JSON numbers are json.Number | int | int64 | float64, * JSON string is a Go string, * JSON array is a Go []interface{}, * JSON object is a Go map[st

(d interface{})

Source from the content-addressed store, hash-verified

973// * JSON array is a Go []interface{},
974// * JSON object is a Go map[string]interface{}.
975func MakeJSON(d interface{}) (JSON, error) {
976 switch v := d.(type) {
977 case json.Number:
978 return FromNumber(v)
979 case string:
980 return FromString(v), nil
981 case bool:
982 return FromBool(v), nil
983 case nil:
984 return NullJSONValue, nil
985 case []interface{}:
986 return fromArray(v)
987 case map[string]interface{}:
988 return fromMap(v)
989 // The below are not used by ParseJSON, but are provided for ease-of-use when
990 // constructing Datums.
991 case int:
992 return FromInt(v), nil
993 case int64:
994 return FromInt64(v), nil
995 case float64:
996 return FromFloat64(v)
997 case JSON:
998 // If we get passed a JSON, just accept it. This is useful in cases like the
999 // random JSON generator.
1000 return v, nil
1001 }
1002 return nil, errors.AssertionFailedf("unknown value type passed to MakeJSON: %T", d)
1003}
1004
1005// This value was determined through some rough experimental results as a good
1006// place to start doing binary search over a linear scan.

Callers 5

MakeDJSONFunction · 0.92
RandomFunction · 0.85
ParseJSONFunction · 0.85
fromArrayFunction · 0.85
fromMapFunction · 0.85

Calls 8

FromNumberFunction · 0.85
FromBoolFunction · 0.85
fromArrayFunction · 0.85
fromMapFunction · 0.85
FromStringFunction · 0.70
FromIntFunction · 0.70
FromInt64Function · 0.70
FromFloat64Function · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…