ParseJSON takes a string of JSON and returns a JSON value.
(s string)
| 662 | |
| 663 | // ParseJSON takes a string of JSON and returns a JSON value. |
| 664 | func 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. |
no test coverage detected
searching dependent graphs…