The 8 most common JSON errors and how to fix them

Trailing commas, single quotes, comments, malformed numbers… what each error means and how to fix it.

Last reviewed:

Why JSON is so strict

JSON began as a subset of JavaScript designed for exchanging data between programs, and its specification (RFC 8259) is deliberately tiny: no comments, no optional commas and no special types. That rigidity is a strength, because every language reads it the same way, but it means a single misplaced character invalidates the whole document.

Most errors come from writing JSON by hand “as if it were JavaScript” or copying it from a configuration file that allows more, such as JSON5 or YAML.

The errors you'll see again and again

These account for nine out of ten invalid JSON documents:

  • Trailing comma: [1, 2, 3,] or {"a": 1,}. Remove the comma before ] or }.
  • Single quotes: {'id': 1}. Strings and keys always use double quotes.
  • Unquoted keys: {id: 1}. Write {"id": 1}.
  • Comments: // and /* */ aren't allowed. If you need notes, use a key such as "_comment".
  • Capitalized or non-existent literals: True, False, None, undefined or NaN. Use true, false or null.
  • Malformed numbers: leading zeros (007), a leading +, .5 without a zero or 1. without decimals.
  • Line breaks inside a string: they must be written as \n.
  • Unescaped backslashes, typical in Windows paths: write C:\\Users instead of C:\Users.

How to read the error message

Browsers usually say something like “Unexpected token } in JSON at position 42”. The position is where the parser noticed, which isn't always where the mistake is: a missing comma is detected at the next item, and an unclosed quote may surface many lines later.

Our validator turns those messages into a likely cause, gives you the line and column and marks the exact spot, so finding the problem takes a glance.

Things that aren't errors but still bite

JSON can be valid and still cause trouble. Duplicate keys are allowed by the specification, but almost every reader silently keeps only the last value. And integers larger than 2^53 (9,007,199,254,740,991) lose precision in JavaScript: an ID like 12345678901234567890 quietly becomes a different number.

If you work with very long IDs, send them as strings ("12345678901234567890") rather than numbers.

A no-surprises workflow

Before pasting JSON into an API or a configuration file:

  • Validate it and fix the first error shown; one error often causes the rest.
  • Pretty-print it to review the structure at a glance.
  • If you're comparing two versions, sort the keys so differences stand out.
  • Minify it only at the end, if size matters.

Tools in this guide