Invalid JSON: common causes
October 30, 2026 · 12 min read
Invalid JSON blocks deploys, breaks webhooks, and wastes hours when a log line is almost JSON but not quite. RFC 8259 is strict: no comments, no trailing commas, double-quoted keys, and precise escaping. This article lists causes parsers report most often and how to fix them before schema validation.
Missing braces, brackets, or quotes
A missing } or ] makes the parser reach EOF still inside a structure. Copy-paste from Slack often truncates the tail. Paste the blob into the JSON validator - the error position points near the unclosed block.
// Invalid - missing closing brace
{ "ok": true, "items": [1, 2]
// Valid
{ "ok": true, "items": [1, 2] }
Trailing commas and lone commas
JavaScript allows [1,2,]; JSON does not. Generators that emit trailing commas from template loops need a final-element flag. Likewise, double commas ,, or a comma before } fail immediately.
Unescaped characters in strings
- Control characters must be escaped as \n, \t, \uXXXX.
- Backslashes and quotes inside strings need \\ and \".
- Single-quoted strings are invalid - JSON requires double quotes.
BOM, smart quotes, and truncated UTF-8
Word processors insert curly quotes that parsers reject. A UTF-8 BOM at file start can confuse strict parsers. Ensure files are UTF-8 without BOM for APIs; convert legacy exports before ingestion.
A practical fix workflow
Validate syntax first, then schema. Minify only after valid - use JSON formatter to pretty-print once clean. Store golden fixtures in CI so invalid JSON never merges.
FAQ
- Why does JSON.parse fail on valid-looking config?
- Often trailing commas, comments, or single quotes from JavaScript config styles.
- Can JSON have comments?
- Standard JSON no. Use JSONC in editors or separate comment fields in config.
- Are NaN and Infinity allowed?
- No in RFC 8259. Use null or strings if you must represent non-finite values.
- Does order of keys matter for validity?
- No for parsing; duplicate keys are discouraged and last-wins in many parsers.
Related: Common JSON validation errors · JSON Schema tutorial · JSON minification · How to validate JSON online