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

Function MakeJSON

pkg/util/json/json.go:1970–1998  ·  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

1968// * JSON array is a Go []interface{},
1969// * JSON object is a Go map[string]interface{}.
1970func MakeJSON(d interface{}) (JSON, error) {
1971 switch v := d.(type) {
1972 case json.Number:
1973 return FromNumber(v)
1974 case string:
1975 return FromString(v), nil
1976 case bool:
1977 return FromBool(v), nil
1978 case nil:
1979 return NullJSONValue, nil
1980 case []interface{}:
1981 return fromArray(v)
1982 case map[string]interface{}:
1983 return fromMap(v)
1984 // The below are not used by ParseJSON, but are provided for ease-of-use when
1985 // constructing Datums.
1986 case int:
1987 return FromInt(v), nil
1988 case int64:
1989 return FromInt64(v), nil
1990 case float64:
1991 return FromFloat64(v)
1992 case JSON:
1993 // If we get passed a JSON, just accept it. This is useful in cases like the
1994 // random JSON generator.
1995 return v, nil
1996 }
1997 return nil, errors.AssertionFailedf("unknown value type passed to MakeJSON: %T", d)
1998}
1999
2000// This value was determined through some rough experimental results as a good
2001// place to start doing binary search over a linear scan.

Callers 7

MakeDJSONFunction · 0.92
RandGenFunction · 0.85
RandomFunction · 0.85
doRandomJSONFunction · 0.85
parseJSONGoStdFunction · 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…