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

Function GetBoolean

parser.go:2108–2123  ·  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

2106// If key data type do not match, it will return error.
2107// SYS-REQ-005, SYS-REQ-079
2108func GetBoolean(data []byte, keys ...string) (val bool, err error) {
2109 v, t, _, e := Get(data, keys...)
2110
2111 if e != nil {
2112 return false, e
2113 }
2114
2115 if t != Boolean {
2116 if t == Null {
2117 return false, NullValueError
2118 }
2119 return false, fmt.Errorf("Value is not a boolean: %s", string(v))
2120 }
2121
2122 return ParseBoolean(v)
2123}
2124
2125// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
2126// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

Calls 2

GetFunction · 0.85
ParseBooleanFunction · 0.85