712Tools
5 min read

Why your JSON won't parse (and how to fix it in 30 seconds)

Trailing commas, unquoted keys, single quotes, comments โ€” the five errors that break 90% of hand-written JSON, and how to catch them without a build step.

The five things that break JSON

Every "unexpected token" error you hit while wrestling with JSON is almost certainly one of these:

  1. A trailing comma after the last item in an array or object.
  2. Unquoted keys ({name: "x"} instead of {"name": "x"}).
  3. Single quotes instead of double.
  4. Comments (// or /* */) โ€” JSON has no comment syntax.
  5. Undefined or NaN values โ€” JSON only allows numbers, strings, booleans, null, arrays, and objects.

JavaScript source code allows all five. JSON does not. That mismatch is the source of ~90% of "why won't this parse" pain.

The 30-second workflow

Paste the JSON into JSON Formatter. The validator marks the exact line and column where parsing failed. Fix that one character. Repeat until it's clean. This is dramatically faster than eyeballing a 500-line config trying to spot a missing comma.

For huge files, the trick is bisection: cut the file in half, paste one half, see which half fails, repeat. A megabyte-scale JSON with a single trailing comma is a five-minute problem this way.

JSON5 and JSONC are the same problem

Two "friendlier" JSON dialects tempt everyone: JSON5 (allows comments, trailing commas, single quotes) and JSONC (JSON with comments โ€” used by VS Code). They're wonderful to write and disastrous to interchange, because most tools that eat JSON don't eat JSON5.

If you control both ends of the pipe, JSON5 is fine. If you're sending JSON to an API, a database, or any third party, stick to strict JSON โ€” the format that has actually been standardized (RFC 8259) and has parsers everywhere.

Common gotchas beyond syntax

Even after parsing succeeds, three things bite people:

Number precision. JSON numbers are IEEE 754 doubles. Integers larger than 2^53 (like Twitter IDs or Snowflake IDs) silently lose precision. Send them as strings.

Duplicate keys. The spec says behavior is undefined; most parsers keep the last one. Never rely on this.

BOM at the start of the file. A UTF-8 BOM (\uFEFF) at position 0 makes some parsers choke. Strip it if the file was saved from Notepad or an old editor.

Minify or pretty-print?

Both, at different times:

  • Pretty-print for reading, debugging, or committing to git (diffs are readable per line).
  • Minify for wire transfer or embedding in a script. Typical minification saves 15-40% depending on whitespace density.

JSON Formatter does both โ€” one button toggles between them, and the size reduction is shown.

The privacy angle

The JSON you're debugging is often production data โ€” API responses with user emails, database dumps, config with credentials. Uploading that to a random online formatter is a bad habit. JSON Formatter runs entirely in your browser via the native JSON parser; nothing leaves your device.

Related tools you'll reach for in the same debugging session:

  • URL Encoder โ€” when the JSON is stuffed into a query parameter.
  • Regex Tester โ€” when you need to yank a specific field out of a huge dump.
  • JWT Decoder โ€” when the "JSON" you got back is actually a signed token.

Tools mentioned in this post