MCPcopy
hub / github.com/buger/jsonparser / GetString

Function GetString

parser.go:1239–1259  ·  view source on GitHub ↗

SYS-REQ-002, SYS-REQ-071, SYS-REQ-072, SYS-REQ-073, SYS-REQ-074 GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols If key data type do not match, it will return an error.

(data []byte, keys ...string)

Source from the content-addressed store, hash-verified

1237// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
1238// If key data type do not match, it will return an error.
1239func GetString(data []byte, keys ...string) (val string, err error) {
1240 v, t, _, e := Get(data, keys...)
1241
1242 if e != nil {
1243 return "", e
1244 }
1245
1246 if t != String {
1247 if t == Null {
1248 return "", NullValueError
1249 }
1250 return "", fmt.Errorf("Value is not a string: %s", string(v))
1251 }
1252
1253 // If no escapes return raw content
1254 if bytes.IndexByte(v, '\\') == -1 {
1255 return string(v), nil
1256 }
1257
1258 return ParseString(v)
1259}
1260
1261// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
1262// The offset is the same as in `Get`.

Callers 12

TestGetStringDeterminismFunction · 0.85
TestGetStringNilSafetyFunction · 0.85
TestMutationUnicodeKeysFunction · 0.85
FuzzGetStringFunction · 0.85
TestGetStringFunction · 0.85
TestGetStringEmptyInputFunction · 0.85

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85

Tested by 11

TestGetStringDeterminismFunction · 0.68
TestGetStringNilSafetyFunction · 0.68
TestMutationUnicodeKeysFunction · 0.68
TestGetStringFunction · 0.68
TestGetStringEmptyInputFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…