Developer Tools

7 JSON Mistakes That Break APIs (And How to Catch Them Fast)

Trailing commas, single quotes, NaN — the errors that waste the most debugging time, with the quickest way to find each one.

3 min read·Updated 2026-09-27

JSON's grammar is tiny — six data types and four structural characters — which is exactly why its errors are so annoying: they are always trivial, always your fault, and occasionally buried in a 4,000-line response. Here are the mistakes that cause the most wasted minutes, and how the formatter approach catches them instantly.

1. Trailing commas

{"a": 1, "b": 2,} is legal JavaScript and illegal JSON. Every dynamic language has this trap — objects serialized from code that "looks fine" in the IDE. The parser rejects it with a position; that position is all you need.

2. Single quotes

{'a': 'b'} — JSON requires double quotes on keys and strings. This one migrates from PHP and Python habits and survives code review because single quotes are visually identical at a glance.

3. Unquoted keys

{a: 1} works in JavaScript, fails in JSON. If your config file is consumed by anything other than JSON.parse — Go, a CI script, a feature-flag service — it must be strict.

4. Comments

JSON has no comment syntax. // note or /* */ inside a response is an immediate parse error. Use JSONC only where the consumer explicitly supports it (tsconfig, VS Code settings).

5. NaN, Infinity, undefined

None exist in JSON. Use null for "no value", or convert numbers to strings. Serializers that quietly emit NaN produce payloads that break on the receiving side, not the sending side — worst possible place to fail.

6. The invisible characters problem

Pasting from Word, Slack or a PDF can carry non-breaking spaces (U+00A0) or zero-width joiners. The JSON looks identical but fails at a character you cannot see. Formatting normalizes whitespace and exposes the offender.

7. Numbers formatted for humans

1,000 and .5 are invalid. So are leading zeros (007). JSON numbers follow a strict grammar: optional minus, no commas, digits before or after the point but not both missing.

The fast workflow

  1. Paste the payload into a formatter — pretty-print immediately reveals structural problems.
  2. Read the error line and character — it is nearly always one of the seven above.
  3. Fix, reformat, then minify once valid — minified output is what you ship.

The JSON Formatter & Validator does exactly this loop with explicit error positions. When the payload is tabular, convert it with the JSON to CSV Converter for a spreadsheet review — mismatches in row shape become visible immediately. For config migrations, the JSON ⇄ YAML Converter handles both directions.

Prevention beats detection

  • Lint JSON in CI — jq . file.json exits non-zero on bad syntax and takes milliseconds.
  • Use schema validation ($schema, JSON Schema) so wrong shapes fail too, not just wrong syntax.
  • Never hand-edit production payloads in a text editor without a formatter open next to it.

Frequently asked questions

Why does my JSON parse locally but fail over HTTP? Truncation or double-encoding — check the raw response bytes (curl) before blaming the payload.

Is trailing comma ever okay? In JSON5 or ECMAScript objects, yes; in data interchange, never. The consumer decides the dialect, not the author.

Tools used in this guide

Related guides