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

Function ParseBoolean

parser.go:2033–2042  ·  view source on GitHub ↗

ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness) SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066

(b []byte)

Source from the content-addressed store, hash-verified

2031// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
2032// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066
2033func ParseBoolean(b []byte) (bool, error) {
2034 switch {
2035 case bytes.Equal(b, trueLiteral):
2036 return true, nil
2037 case bytes.Equal(b, falseLiteral):
2038 return false, nil
2039 default:
2040 return false, MalformedValueError
2041 }
2042}
2043
2044// ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
2045// SYS-REQ-014, SYS-REQ-038, SYS-REQ-060, SYS-REQ-063, SYS-REQ-067

Calls

no outgoing calls