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

Function ParseJSON

postgres/parser/json/json.go:714–735  ·  view source on GitHub ↗

ParseJSON takes a string of JSON and returns a JSON value.

(s string)

Source from the content-addressed store, hash-verified

712
713// ParseJSON takes a string of JSON and returns a JSON value.
714func ParseJSON(s string) (JSON, error) {
715 // This goes in two phases - first it parses the string into raw interface{}s
716 // using the Go encoding/json package, then it transforms that into a JSON.
717 // This could be faster if we wrote a parser to go directly into the JSON.
718 var result interface{}
719 decoder := json.NewDecoder(strings.NewReader(s))
720 // We want arbitrary size/precision decimals, so we call UseNumber() to tell
721 // the decoder to decode numbers into strings instead of float64s (which we
722 // later parse using apd).
723 decoder.UseNumber()
724 err := decoder.Decode(&result)
725 if err != nil {
726 err = errors.Handled(err)
727 err = errors.Wrap(err, "unable to decode JSON")
728 err = pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
729 return nil, err
730 }
731 if decoder.More() {
732 return nil, errTrailingCharacters
733 }
734 return MakeJSON(result)
735}
736
737// EncodeInvertedIndexKeys takes in a key prefix and returns a slice of inverted index keys,
738// one per unique path through the receiver.

Callers 3

jsonStringMethod · 0.92
ParseDJSONFunction · 0.92
FromSpatialObjectFunction · 0.85

Calls 3

WithCandidateCodeFunction · 0.92
MakeJSONFunction · 0.85
NewDecoderMethod · 0.45

Tested by

no test coverage detected