ParseJSON takes a string of JSON and returns a JSON value.
(s string)
| 712 | |
| 713 | // ParseJSON takes a string of JSON and returns a JSON value. |
| 714 | func 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. |
no test coverage detected