JSON Boolean / Null Literal
Match JSON `true`, `false`, and `null` literal values, with word boundaries to avoid partial matches.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b(true|false|null)\\b", "g");
const input = "{\"active\": true, \"deleted\": false, \"deleted_at\": null}";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b(true|false|null)\b")
input_text = "{\"active\": true, \"deleted\": false, \"deleted_at\": null}"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
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.
Pattern
\b(true|false|null)\b (flags: g)Raw source: \b(true|false|null)\b
How it works
Examples
Input
{"active": true, "deleted": false, "deleted_at": null}Matches
truefalsenull
Input
active=true; expired=falseMatches
truefalse
Input
no literalsNo match
—Common use cases
- •Quick filtering of JSON-shaped log lines
- •Lightweight type-detection in observability pipelines
- •Documentation generation from JSON schemas
- •Test case extraction from inline JSON examples
Related patterns
JSON Key-Value Pair (Simple)
Text ProcessingExtract simple `"key": value` pairs from JSON-ish text (strings, numbers, booleans, null).
JSON Number (Strict)
Text ProcessingMatch JSON-spec numbers — disallows leading zeros (no `01`), allows decimals and exponents.
JavaScript Template Literal Placeholder
Text ProcessingMatch `${expression}` placeholders inside JavaScript template literals.
Hashtag
Text ProcessingMatch hashtags (# followed by word characters) in social media posts, including accented Latin characters.