JSON Syntax Validation: Common Traps, Escaping & Schema Rules
Diagnose syntax errors in JSON payloads. Learn RFC 8259 formatting standards, trailing comma errors, and unescaped quote resolution.
Key takeaways
- JSON (RFC 8259) is significantly stricter than standard JavaScript object literals.
- Trailing commas after the last item in an object or array will cause JSON.parse() to throw an exception.
- Single quotes are completely invalid in JSON; both keys and string values must use double quotes (").
- Large 64-bit integers can lose precision in JavaScript JSON parsers unless passed as strings.
Companion utility
Try JSON Formatter & Validator
Use the browser utility for the same task, then return here for the implementation details.
1. The Strict Rules of JSON (RFC 8259)
We have all experienced it: a single missing quote or a stray comma on line 400 breaks an API payload, and JSON.parse() throws an unhelpful error. Although JSON originated from JavaScript syntax, it enforces much stricter validation: 1. Trailing Commas: In JavaScript, { a: 1, } is completely valid. In JSON, trailing commas are strictly forbidden. 2. Single Quotes: Keys and strings must exclusively use double quotes ("). Writing {'key': 'value'} will always fail. 3. Unquoted Keys: Every object property name must be enclosed in double quotes.
2. Formatting for Human Inspection vs Minification
Pretty-printed JSON is easier to inspect, while minified JSON reduces unnecessary whitespace. The actual bandwidth saving depends on the original formatting, compression, and transport settings, so measure the payload rather than assuming a fixed percentage.
Rana Jawad
Principal Systems Architect at ToolNara. The guides focus on browser runtime behavior, standards, and engineering trade-offs.
View author profile