JSON Key-Value Pair (Simple) in PY
Extract simple `"key": value` pairs from JSON-ish text (strings, numbers, booleans, null).
Try it in the PY tester →Pattern
regexPY
"([^"\\]+)"\s*:\s*("[^"\\]*"|-?\d+(?:\.\d+)?|true|false|null) (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"\"([^\"\\\\]+)\"\\s*:\\s*(\"[^\"\\\\]*\"|-?\\d+(?:\\.\\d+)?|true|false|null)")
input_text = "{\"name\": \"alice\", \"age\": 30, \"active\": true}"
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
"([^"\\]+)" captures the key — non-quote, non-backslash chars (so escaped quotes break the match — by design, this is a quick parser, not a strict one). \s*:\s* matches the separator. The value group covers strings, signed integers/decimals, true, false, and null. Use a real JSON parser for production!
Examples
Input
{"name": "alice", "age": 30, "active": true}Matches
"name": "alice""age": 30"active": true
Input
"timeout": 5000, "retries": nullMatches
"timeout": 5000"retries": null
Input
no json hereNo match
—