MCPcopy Create free account
hub / github.com/buger/jsonparser / Get

Method Get

reader_parser.go:52–85  ·  view source on GitHub ↗

Get returns the value addressed by keys without loading the whole document. As with the package-level Get, string values are returned without quotes but retain their JSON escapes. SYS-REQ-116

(keys ...string)

Source from the content-addressed store, hash-verified

50// retain their JSON escapes.
51// SYS-REQ-116
52func (rp *ReaderParser) Get(keys ...string) (value []byte, vt ValueType, err error) {
53 for _, key := range keys {
54 if key == "" {
55 return nil, NotExist, KeyPathNotFoundError
56 }
57 }
58
59 if err := rp.skipWhitespace(); err != nil {
60 if err == io.EOF {
61 return nil, NotExist, KeyPathNotFoundError
62 }
63 return nil, NotExist, err
64 }
65
66 var raw []byte
67 if len(keys) == 0 {
68 raw, err = rp.captureValue()
69 } else {
70 var found bool
71 found, raw, err = rp.findValue(keys, 0)
72 if err == nil && !found {
73 err = KeyPathNotFoundError
74 }
75 }
76 if err != nil {
77 return nil, NotExist, err
78 }
79
80 value, vt, _, err = rp.config.Get(raw)
81 if err != nil {
82 return value, vt, err
83 }
84 return value, vt, nil
85}
86
87// GetString returns and decodes the string addressed by keys.
88// SYS-REQ-116

Callers 7

GetStringMethod · 0.95
TestReaderParserGetFunction · 0.95
TestReaderParserEmptyFunction · 0.95
ArrayEachMethod · 0.45

Calls 3

skipWhitespaceMethod · 0.95
captureValueMethod · 0.95
findValueMethod · 0.95

Tested by 5

TestReaderParserGetFunction · 0.76
TestReaderParserEmptyFunction · 0.76