Python (re)

JSON Boolean / Null Literal in PY

Match JSON `true`, `false`, and `null` literal values, with word boundaries to avoid partial matches.

Try it in the PY tester →

Pattern

regexPY
\b(true|false|null)\b   (flags: g)

Python (re) code

pyPython
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+.

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

  • true
  • false
  • null

Input

active=true; expired=false

Matches

  • true
  • false

Input

no literals

No match

Same pattern, other engines

← Back to JSON Boolean / Null Literal overview (all engines)