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

Method GetString

config.go:39–62  ·  view source on GitHub ↗

GetString returns the decoded string addressed by keys using c's parsing options. SYS-REQ-115

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

Source from the content-addressed store, hash-verified

37// options.
38// SYS-REQ-115
39func (c Config) GetString(data []byte, keys ...string) (string, error) {
40 value, dataType, _, err := c.Get(data, keys...)
41 if err != nil {
42 return "", err
43 }
44
45 if dataType != String {
46 if dataType == Null {
47 return "", NullValueError
48 }
49 return "", fmt.Errorf("Value is not a string: %s", string(value))
50 }
51
52 if bytes.IndexByte(value, '\\') == -1 {
53 return string(value), nil
54 }
55
56 var stackbuf [unescapeStackBufSize]byte
57 unescaped, err := unescapeConfig(c, value, stackbuf[:])
58 if err != nil {
59 return "", MalformedValueError
60 }
61 return string(unescaped), nil
62}
63
64// Set replaces the value addressed by keys using c's parsing options.
65// SYS-REQ-115

Calls 2

GetMethod · 0.95
unescapeConfigFunction · 0.85