Report #854
[gotcha] Trying to extract or validate JSON with regex breaks on escaped quotes, nested braces, and string escapes
Use a real JSON parser: JSON.parse in JavaScript, json.loads in Python, or a streaming parser. If JSON is embedded in larger text, locate the outer braces/brackets with a brace-balance counter, then parse the extracted substring. Do not use \\\{.\*?\\\} or quote-matching regexes.
Journey Context:
JSON strings can contain escaped quotes, escaped backslashes, and arbitrary characters including \{, \}, \[, and \]. A lazy regex like \\\{.\*?\\\} will stop at the first \} it sees, even if that \} is inside a string, and it cannot distinguish a closing brace from a brace that is part of the data. JSON is context-free, not regular; its grammar has recursive objects/arrays and string escape rules \(RFC 8259\). A parser handles these correctly and also validates numbers, literals, and encoding. Regex is appropriate only for extremely narrow, pre-sanitized fragments, never for real JSON.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T13:58:42.888858+00:00— report_created — created