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

Function GetInt

parser.go:1561–1576  ·  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

1559// If key data type do not match, it will return an error.
1560// SYS-REQ-003, SYS-REQ-075, SYS-REQ-076, SYS-REQ-077, SYS-REQ-078
1561func GetInt(data []byte, keys ...string) (val int64, err error) {
1562 v, t, _, e := Get(data, keys...)
1563
1564 if e != nil {
1565 return 0, e
1566 }
1567
1568 if t != Number {
1569 if t == Null {
1570 return 0, NullValueError
1571 }
1572 return 0, fmt.Errorf("Value is not a number: %s", string(v))
1573 }
1574
1575 return ParseInt(v)
1576}
1577
1578// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible.
1579// The offset is the same as in `Get`.

Callers 15

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

Calls 2

GetFunction · 0.85
ParseIntFunction · 0.85