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

Function GetBoolean

parser.go:2054–2069  ·  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

2052// If key data type do not match, it will return error.
2053// SYS-REQ-005, SYS-REQ-079
2054func GetBoolean(data []byte, keys ...string) (val bool, err error) {
2055 v, t, _, e := Get(data, keys...)
2056
2057 if e != nil {
2058 return false, e
2059 }
2060
2061 if t != Boolean {
2062 if t == Null {
2063 return false, NullValueError
2064 }
2065 return false, fmt.Errorf("Value is not a boolean: %s", string(v))
2066 }
2067
2068 return ParseBoolean(v)
2069}
2070
2071// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
2072// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

Calls 2

GetFunction · 0.85
ParseBooleanFunction · 0.85