← BlogCommon JSON Errors: Find and Fix Them Fast
Why JSON Error Messages Are So Unhelpful
JSON's grammar is brutally strict: keys need double quotes, comments don't exist, and no trailing comma after the last item. The parser stops at the first offending character — but the line and column it reports usually point at the symptom, not the cause. The real problem typically sits on the line before.
The Seven Most Common Errors
1. Trailing comma
{
"name": "widget",
"price": 9.9, ← this comma breaks the parser
}
2. Single quotes instead of double
{ 'name': 'widget' } ← JSON only accepts double quotes
3. Unquoted keys
{ name: "widget" } ← must be "name"
4. Comments
The JSON standard (RFC 8259) allows no comments at all — both // and /* */ are syntax errors. Copy-pasting from a JavaScript object literal is how most people trip on this.
5. Mismatched brackets
{ "items": [1, 2, 3 } ← missing the closing ]
6. Illegal numbers
Leading zeros (012), hex (0x1F), NaN, and Infinity are all invalid. JSON numbers are plain decimal, optionally signed and fractional. Nothing else.
7. Multiple root values
One JSON document holds exactly one root value. Two objects side by side — {"a":1} {"b":2} — are an error; wrap them in an array or a single object.
Let a Formatter Locate It: 10× Faster Than Reading Errors
Paste the whole document into a JSON formatter and the parser flags the exact line and column. A successful format also re-indents everything, so structural problems — wrong nesting, duplicate keys — jump out visually. Build the habit: when an API response fails, format it before debugging it.
Prevention Beats Repair
- Install a JSON validation extension in your editor — VS Code flags errors with red squiggles in real time
- Generate JSON from JavaScript with JSON.stringify() instead of hand-writing it
- Run every API JSON response through a formatter before it reaches business code
- For config files, consider JSON5 or YAML — both support comments and cut down on hand-edited JSON
FAQ
- How is JSON different from a JavaScript object?
- JSON is its own data format — a subset of JS object syntax: keys require double quotes, there are no comments, variables, or functions. Valid JS literals aren't always valid JSON.
- Can YAML replace JSON?
- For config files, yes — comments and readability win. For API payloads, JSON remains the mainstream choice with the broadest parser support. See our JSON vs XML vs YAML comparison.