toolgix

Common JSON Errors and How to Fix Them

JSON looks like JavaScript, but it is stricter. Almost every “Unexpected token” error comes from one of a handful of habits that JavaScript allows and JSON does not.

The usual suspects

MistakeInvalidValid
Trailing comma{"a": 1,}{"a": 1}
Single quotes{'a': 1}{"a": 1}
Unquoted keys{a: 1}{"a": 1}
Comments{"a": 1 // note}Remove comments (or use a format that allows them)
NaN / Infinity / undefined{"a": NaN}{"a": null} or a string
Leading zeros{"n": 007}{"n": 7}
Raw line break in a stringa string split across lineswrite \n inside the string
Capitalised literalsTrue, Nulltrue, null

How to find the error fast

  1. Paste the text into JSON Formatter. It validates as you type and points to the line and column of the first error.
  2. Look just before the reported position: the parser notices a problem one character after the real mistake (a missing comma shows up at the next key).
  3. Fix and repeat — there may be more than one error.

Subtle problems that still parse

  • Duplicate keys like {"a":1,"a":2}. RFC 8259 says names SHOULD be unique; different parsers keep the first or the last value. Avoid them.
  • Big integers above 2^53 (9,007,199,254,740,992) lose precision in JavaScript. Send IDs as strings.
  • A byte-order mark at the start of a file can break some parsers. Save files as UTF-8 without BOM.

When JSON is the wrong format

If you need comments or trailing commas in a configuration file, use a format designed for it (YAML, TOML or JSON5) and convert to JSON for machines. YAML to JSON does that conversion in your browser.

Sources

Related tools

More guides

All guides →

Categories

Recent and favourites

Tools you open appear here, and tools you star with “Favourite” stay at the top. This list is kept only in this browser.

Browse all 78 tools

↑ ↓ to moveEnter to openEsc to close