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

Function ParseBoolean

parser.go:2073–2082  ·  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

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
2073func ParseBoolean(b []byte) (bool, error) {
2074 switch {
2075 case bytes.Equal(b, trueLiteral):
2076 return true, nil
2077 case bytes.Equal(b, falseLiteral):
2078 return false, nil
2079 default:
2080 return false, MalformedValueError
2081 }
2082}
2083
2084// ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
2085// SYS-REQ-014, SYS-REQ-038, SYS-REQ-060, SYS-REQ-063, SYS-REQ-067

Calls

no outgoing calls