JSON Formatting: Why It Breaks and How to Fix It

The five reasons JSON.parse fails, how to read the error position, and the fastest way to validate a payload before shipping it.

2026-10-28 · Format

The five common failures

Trailing commas, single quotes, unquoted keys, comments and control characters. Every one is valid JavaScript and invalid JSON — which is why copied objects break.

Reading the error

A JSON error message ends with a position. Count from the start (or the end if negative) and look one character before the reported index: that is nearly always the offending comma or bracket.

Validate before shipping

Paste the payload into the formatter, fix the highlight, then copy the minified version back. Formatting makes diffs readable; minifying makes the payload smaller.

Why does my JSON work in JS but not in a parser?
JavaScript object literals allow trailing commas and unquoted keys; JSON does not.
Does formatting change the data?
No — whitespace is insignificant in JSON.