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{})
| 973 | // * JSON array is a Go []interface{}, |
| 974 | // * JSON object is a Go map[string]interface{}. |
| 975 | func 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. |
no test coverage detected
searching dependent graphs…