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

Function GetInt

parser.go:2033–2048  ·  view source on GitHub ↗

GetInt returns the value retrieved by `Get`, cast to a int64 if possible. If key data type do not match, it will return an error. SYS-REQ-003, SYS-REQ-075, SYS-REQ-076, SYS-REQ-077, SYS-REQ-078

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

Source from the content-addressed store, hash-verified

2031// If key data type do not match, it will return an error.
2032// SYS-REQ-003, SYS-REQ-075, SYS-REQ-076, SYS-REQ-077, SYS-REQ-078
2033func GetInt(data []byte, keys ...string) (val int64, err error) {
2034 v, t, _, e := Get(data, keys...)
2035
2036 if e != nil {
2037 return 0, e
2038 }
2039
2040 if t != Number {
2041 if t == Null {
2042 return 0, NullValueError
2043 }
2044 return 0, fmt.Errorf("Value is not a number: %s", string(v))
2045 }
2046
2047 return ParseInt(v)
2048}
2049
2050// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible.
2051// The offset is the same as in `Get`.

Callers 15

BenchmarkJsonParserSmallFunction · 0.92
BenchmarkJsonParserLargeFunction · 0.92
GetIntMethod · 0.85
TestTypedGetterNilSafetyFunction · 0.85
FuzzPathMutationFunction · 0.85
FuzzGetIntFunction · 0.85

Calls 2

GetFunction · 0.85
ParseIntFunction · 0.85