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

Function ParseBoolean

parser.go:1941–1950  ·  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

1939// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
1940// SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066
1941func ParseBoolean(b []byte) (bool, error) {
1942 switch {
1943 case bytes.Equal(b, trueLiteral):
1944 return true, nil
1945 case bytes.Equal(b, falseLiteral):
1946 return false, nil
1947 default:
1948 return false, MalformedValueError
1949 }
1950}
1951
1952// ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
1953// SYS-REQ-014, SYS-REQ-038, SYS-REQ-060, SYS-REQ-063, SYS-REQ-067

Calls

no outgoing calls