JSON Boolean / Null Literal in GO
Match JSON `true`, `false`, and `null` literal values, with word boundaries to avoid partial matches.
Try it in the GO tester →Pattern
regexGO
\b(true|false|null)\b (flags: g)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b(true|false|null)\b`)
input := `{"active": true, "deleted": false, "deleted_at": null}`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
How the pattern works
\b is a word boundary on both sides so we don't match inside `nullable` or `falsey`. (true|false|null) captures one of the three JSON literals. Useful for quick log scraping or schema-detection passes when full JSON parsing is overkill.
Examples
Input
{"active": true, "deleted": false, "deleted_at": null}Matches
truefalsenull
Input
active=true; expired=falseMatches
truefalse
Input
no literalsNo match
—