MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / ParseJSON

Function ParseJSON

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

662
663// ParseJSON takes a string of JSON and returns a JSON value.
664func ParseJSON(s string) (JSON, error) {
665 // This goes in two phases - first it parses the string into raw interface{}s
666 // using the Go encoding/json package, then it transforms that into a JSON.
667 // This could be faster if we wrote a parser to go directly into the JSON.
668 var result interface{}
669 decoder := json.NewDecoder(strings.NewReader(s))
670 // We want arbitrary size/precision decimals, so we call UseNumber() to tell
671 // the decoder to decode numbers into strings instead of float64s (which we
672 // later parse using apd).
673 decoder.UseNumber()
674 err := decoder.Decode(&result)
675 if err != nil {
676 err = errors.Handled(err)
677 err = errors.Wrap(err, "unable to decode JSON")
678 err = pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation)
679 return nil, err
680 }
681 if decoder.More() {
682 return nil, errTrailingCharacters
683 }
684 return MakeJSON(result)
685}
686
687// EncodeInvertedIndexKeys takes in a key prefix and returns a slice of inverted index keys,
688// one per unique path through the receiver.

Callers 3

jsonStringMethod · 0.92
ParseDJSONFunction · 0.92
FuzzParseJSONFunction · 0.85

Calls 3

WithCandidateCodeFunction · 0.92
MakeJSONFunction · 0.85
NewDecoderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…