How to Fix Invalid JSON and Understand the Error Messages

Parsers give you cryptic messages like "unexpected token". In practice almost every broken JSON file comes from the same small set of mistakes.

JSON looks forgiving. It is a list of labeled values, that is all. But it has a short list of strict rules, and a parser quits at the first broken one. The good news is that the same handful of mistakes causes nearly every error you will see, so you can learn to spot them in seconds.

The six most common JSON mistakes

1. Trailing commas

JSON does not allow a comma after the last item. JavaScript does, so a shortcut or a habit carries it over and the parser rejects the file.

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

Fix: delete the comma before the closing brace or bracket.

2. Single quotes instead of double quotes

JSON demands double quotes for keys and string values. Code copied out of JavaScript or a Python dictionary is full of single quotes, and none of them are valid here.

{ 'name': 'Ada' }

3. Unquoted keys

JavaScript lets you write { name: "Ada" }. JSON forces every key to be quoted.

{ name: "Ada" }

4. Comments

There is no comment syntax in JSON. Files like tsconfig.json that allow // comments are a different format called JSONC. A strict JSON parser will always reject them.

5. Missing or mismatched brackets

Every { needs a matching } and every [ a matching ]. Truncated API responses and copy paste slip ups are the usual cause, and the error appears at the very end of the file.

6. Invisible characters

This one is evil. Copy text out of Word, Google Docs or Slack and the quotes turn curly, "smart quotes" that look identical on screen but break the parser. A byte order mark at the start of a file does the same, blowing up at position 0.

Decoding the error messages

Error messageWhat it meansThe fix
Unexpected token }Trailing comma, or a stray closing braceDelete the comma before it
Unexpected token 'Single quotes used as string delimitersReplace them with double quotes
Unexpected token nUnquoted object keyWrap the key in double quotes
Unexpected token /A // or /* */ commentDelete every comment
Unexpected end of JSON inputA closing bracket is missingAdd the missing } or ]
Expected , or } after propertyMissing comma between valuesAdd the comma between items
Error at position 0BOM or hidden character at the startRe-save without BOM, or retype the first line

The parser always stops at the first problem it meets, but the real mistake is often just before that spot. If the error lands on line 8, check line 7 for a missing comma, a lone quote, or a bracket that never closed.

The practical fix workflow

  • Paste the broken JSON into a formatter that reports line and column.
  • Fix the very first error it reports, then run it again.
  • Repeat. The first error often hides the next one, and they surface one at a time.

If the file came from a log or a database export that got cut off mid way, no tool can invent the missing values. In that case, fix the producer so it writes complete records, which is a one line change in most log shippers.

Fix and format JSON in seconds

Paste it, and the formatter points straight at the first broken line.

Open JSON Formatter

Frequently asked questions

Can JSON files have comments?

No. JSON has no comment syntax by design. Files that allow // comments are called JSONC or JSON5, and a strict JSON parser will reject them.

What does unexpected token in JSON at position 0 mean?

It usually means the file starts with a hidden character like a byte order mark, or the content does not start with a valid JSON value such as an object brace or array bracket.

Are trailing commas allowed in JSON?

No. A comma after the last item in an object or array is invalid JSON. JavaScript allows it, JSON does not, which makes it the single most common JSON error.