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

Function GetString

parser.go:1515–1535  ·  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

1513// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols
1514// If key data type do not match, it will return an error.
1515func GetString(data []byte, keys ...string) (val string, err error) {
1516 v, t, _, e := Get(data, keys...)
1517
1518 if e != nil {
1519 return "", e
1520 }
1521
1522 if t != String {
1523 if t == Null {
1524 return "", NullValueError
1525 }
1526 return "", fmt.Errorf("Value is not a string: %s", string(v))
1527 }
1528
1529 // If no escapes return raw content
1530 if bytes.IndexByte(v, '\\') == -1 {
1531 return string(v), nil
1532 }
1533
1534 return ParseString(v)
1535}
1536
1537// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible.
1538// The offset is the same as in `Get`.

Calls 2

GetFunction · 0.85
ParseStringFunction · 0.85