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

Function GetBoolean

parser.go:1582–1597  ·  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

1580// If key data type do not match, it will return error.
1581// SYS-REQ-005, SYS-REQ-079
1582func GetBoolean(data []byte, keys ...string) (val bool, err error) {
1583 v, t, _, e := Get(data, keys...)
1584
1585 if e != nil {
1586 return false, e
1587 }
1588
1589 if t != Boolean {
1590 if t == Null {
1591 return false, NullValueError
1592 }
1593 return false, fmt.Errorf("Value is not a boolean: %s", string(v))
1594 }
1595
1596 return ParseBoolean(v)
1597}
1598
1599// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
1600// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

Calls 2

GetFunction · 0.85
ParseBooleanFunction · 0.85