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

Function GetBoolean

parser.go:1995–2010  ·  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

1993// If key data type do not match, it will return error.
1994// SYS-REQ-005, SYS-REQ-079
1995func GetBoolean(data []byte, keys ...string) (val bool, err error) {
1996 v, t, _, e := Get(data, keys...)
1997
1998 if e != nil {
1999 return false, e
2000 }
2001
2002 if t != Boolean {
2003 if t == Null {
2004 return false, NullValueError
2005 }
2006 return false, fmt.Errorf("Value is not a boolean: %s", string(v))
2007 }
2008
2009 return ParseBoolean(v)
2010}
2011
2012// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
2013// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

Calls 2

GetFunction · 0.85
ParseBooleanFunction · 0.85