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

Function GetBoolean

parser.go:1306–1321  ·  view source on GitHub ↗

GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. The offset is the same as in `Get`. If key data type do not match, it will return error. SYS-REQ-005, SYS-REQ-079

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

Source from the content-addressed store, hash-verified

1304// If key data type do not match, it will return error.
1305// SYS-REQ-005, SYS-REQ-079
1306func GetBoolean(data []byte, keys ...string) (val bool, err error) {
1307 v, t, _, e := Get(data, keys...)
1308
1309 if e != nil {
1310 return false, e
1311 }
1312
1313 if t != Boolean {
1314 if t == Null {
1315 return false, NullValueError
1316 }
1317 return false, fmt.Errorf("Value is not a boolean: %s", string(v))
1318 }
1319
1320 return ParseBoolean(v)
1321}
1322
1323// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
1324// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

Callers 6

TestTypedGetterNilSafetyFunction · 0.85
FuzzGetBooleanFunction · 0.85
TestGetBooleanFunction · 0.85

Calls 2

GetFunction · 0.85
ParseBooleanFunction · 0.85

Tested by 5

TestTypedGetterNilSafetyFunction · 0.68
TestGetBooleanFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…