Why does my JSON fail to parse? Common syntax errors and how to fix them fast

By TechCompare · Updated · How we check

Use a JSON formatter to catch syntax errors instantly. The tool highlights the exact position of the error and shows you what the parser expected vs what it found. For VS Code users, the built-in JSON language mode catches most errors with red squigglies before you even try to parse.

JSON parse errors are frustrating because the error messages are usually unhelpful ("Unexpected token at position 847"). The three most common mistakes are trailing commas after the last item in an array or object, using single quotes instead of double quotes for strings, and using unquoted property keys.

Fix it automatically

The JSON Formatter can repair the most common of these mistakes for you. When your text is invalid, a Try to fix button shows up next to the error. It lists every change with its line and column, and nothing changes until you press Apply.

It fixes these:

  • A comma right before a closing bracket or brace is removed.
  • Single quotes around a string or a key become double quotes.
  • A key with no quotes gets double quotes.
  • A comment that starts with // or sits between /* and */ is removed.
  • Python's True, False and None become true, false and null.
  • A closing bracket of the wrong kind, like a ] that closes a {, becomes the right one.
  • JSON that stops right after a value, like a long answer that got cut off, gets the brackets it's missing at the end.

Here's a sample that has all of them. Its last line is cut off:

Before
{
  name: 'Ada', // from the form
  active: True,
  tags: ['a', 'b',},
  scores: [1, 2,

Try to fix lists 13 changes for it. After you press Apply, the input holds this:

After Apply
{
  "name": "Ada", 
  "active": true,
  "tags": ["a", "b"],
  "scores": [1, 2]}

Nothing inside a double quoted string is touched, so a value like "it's None // here" stays exactly as you wrote it. Numbers keep every digit, because the tool edits the text and never turns it into JavaScript values. It only knows the mistakes above, so a missing comma or a bracket missing in the middle stays in the text. If the fixed text still wouldn't parse, the tool shows what's left. Apply still makes the fixes it found, and you fix the rest by hand.

Topic
JSON parse errors
json-errors
Category
Troubleshooting
JSON knowledge base

How this is calculated

Trailing commas are the first thing to check. JavaScript allows them, JSON does not. Developers who write JSON by hand in a JS/TS codebase naturally add trailing commas, then wonder why JSON.parse throws. Single quotes come next: JSON spec requires double quotes for all strings and keys, but JavaScript and Python both accept single-quoted strings, so the habit leaks. Unquoted keys (e.g., {name: "Alice"} instead of {"name": "Alice"}) work fine in JavaScript object literals but fail in strict JSON.

Verdict

Paste the JSON into a formatter before you debug anything by hand.

It catches the three usual mistakes at the exact character position the parser choked on, while the raw JSON.parse error typically reports only an opaque 'Unexpected token at position 847' that doesn't say which one you hit. The three are trailing commas after the last array or object item (legal in JS, illegal in JSON), single quotes instead of double quotes on strings or keys (legal in JS and Python, illegal in JSON), and unquoted property keys (legal in JS object literals, illegal in strict JSON).

VS Code's built-in JSON language mode catches them earlier, with red squiggles before you ever invoke parse. The habit mostly comes from hand-writing JSON in a JS/TS codebase.

More JSON scenarios

Frequently asked questions

Why does JSON not allow trailing commas?
Douglas Crockford, JSON's creator, intentionally kept the spec minimal and strict. Trailing commas cause ambiguity in some parsers and were omitted to keep JSON a true subset of JavaScript's object literal syntax at the time.
What's the most common JSON parse error?
Trailing commas are the usual suspect. JSON spec disallows commas after the last item in arrays or objects, but JavaScript and Python both accept them. The habit leaks, parsers throw, and the error position points at the character after the last comma. Most JSON formatters and linters flag this with red squiggles before you ever try to parse.
Why are single quotes invalid in JSON?
The JSON spec requires double quotes (") for all strings and object keys. Single quotes aren't valid. JavaScript object literals allow single quotes, which is why the habit leaks. JSON.stringify in JS always emits double quotes. JSON parsers always require them. JSON5 and similar extensions relax this, but standard JSON strictly disallows single quotes.