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