MCPcopy Create free account
hub / github.com/dolthub/doltgresql / MakeJSON

Function MakeJSON

postgres/parser/json/json.go:1060–1088  ·  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

1058// * JSON array is a Go []interface{},
1059// * JSON object is a Go map[string]interface{}.
1060func MakeJSON(d interface{}) (JSON, error) {
1061 switch v := d.(type) {
1062 case json.Number:
1063 return FromNumber(v)
1064 case string:
1065 return FromString(v), nil
1066 case bool:
1067 return FromBool(v), nil
1068 case nil:
1069 return NullJSONValue, nil
1070 case []interface{}:
1071 return fromArray(v)
1072 case map[string]interface{}:
1073 return fromMap(v)
1074 // The below are not used by ParseJSON, but are provided for ease-of-use when
1075 // constructing Datums.
1076 case int:
1077 return FromInt(v), nil
1078 case int64:
1079 return FromInt64(v), nil
1080 case float64:
1081 return FromFloat64(v)
1082 case JSON:
1083 // If we get passed a JSON, just accept it. This is useful in cases like the
1084 // random JSON generator.
1085 return v, nil
1086 }
1087 return nil, errors.AssertionFailedf("unknown value type passed to MakeJSON: %T", d)
1088}
1089
1090// This value was determined through some rough experimental results as a good
1091// place to start doing binary search over a linear scan.

Callers 4

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