How to fix the most common JSON syntax errors

Trailing commas, single quotes, comments and unquoted keys cause most invalid JSON. Here is how to spot each one from the error message.

Updated

JSON looks like JavaScript, which is exactly why it breaks: it is much stricter. Almost every “Unexpected token” error comes from one of a handful of habits carried over from code or config files.

Read the error position first

Parsers stop at the first character they cannot accept and report its position, either as a character offset (“at position 42”) or as a line and column. The real mistake is usually just before that point: a missing comma is reported at the start of the next value, not where the comma should have been.

Open the JSON FormatterShows the line and column of the error and a hint for common causes.

Seven mistakes behind most errors

1. Trailing commas

{ "name": "Ada", "role": "admin", }

Remove the comma after the last item in every object and array.

2. Single quotes

{ 'name': 'Ada' }

Strings and keys must use double quotes.

3. Unquoted keys

{ name: "Ada" }

Valid in JavaScript, invalid in JSON. Every key is a double-quoted string: {"name": "Ada"}.

4. Comments

JSON has no comment syntax. Remove // and /* */ blocks, or move notes into a field such as "_comment" if the consumer ignores unknown keys.

5. Values JavaScript allows but JSON does not

undefined, NaN, Infinity, functions and dates are not JSON values. Use null, a number or an ISO date string such as "2026-10-15".

6. Unescaped characters in strings

A double quote or backslash inside a string must be escaped as \" or \\. A real line break inside a string is not allowed; write \n instead. Windows paths are a classic trap: "C:\\Users\\Ada".

7. Numbers with leading zeros or plus signs

007 and +5 are invalid. If leading zeros matter, as with postal codes or IDs, store the value as a string.

When the input is not really JSON

  • JSON Lines / NDJSON: one object per line with no surrounding array. Parse line by line, or wrap the lines in [ ] and separate them with commas.
  • JSON5 or JSONC: formats used by some config files that allow comments and trailing commas. A strict JSON parser will reject them, and that is correct behavior.
  • Escaped JSON: text that starts with "{\" is a JSON string containing JSON. Parse it twice.

A quick debugging routine

  1. Paste the text into a formatter and note the line and column.
  2. Look at the character before the reported position for a missing comma, quote or bracket.
  3. Fix one error at a time and re-validate; later errors are often side effects of the first.
  4. Once it parses, pretty-print it so the structure is easy to review.
All guides