Common JSON Errors and How to Fix Them

Most JSON errors come from trailing commas, single quotes, unquoted keys, comments or missing brackets. Below are the exact messages Chrome and Node.js show for each, what they mean, and how to fix them. Paste your data into the JSON Formatter to validate it.

Why JSON is so strict

JSON looks like JavaScript, but its rules are much tighter: keys must be in double quotes, strings must use double quotes, and there are no comments or trailing commas. One misplaced character makes the whole document invalid, and the error message often points somewhere unexpected. This guide lists the errors you'll see most, with the exact message and the fix.

The messages below are what JSON.parse reports in Chrome, Edge and Node.js (the V8 engine). Firefox, Safari and other languages word them differently, but the causes are the same.

The errors, with real messages

ProblemInvalid JSONError message
Trailing comma{"name": "Ana", "age": 30,}Expected double-quoted property name in JSON at position 26
Single quotes{'name': 'Ana'}Expected property name or '}' in JSON at position 1
Unquoted key{name: "Ana"}Expected property name or '}' in JSON at position 1
Missing comma{"name": "Ana" "age": 30}Expected ',' or '}' after property value in JSON at position 15
Comment{"name": "Ana" // user}Expected ',' or '}' after property value in JSON at position 15
Unclosed brace{"name": "Ana"Expected ',' or '}' after property value in JSON at position 14
NaN or undefined{"score": NaN}Unexpected token 'N', "{"score": NaN}" is not valid JSON
Leading zero{"id": 007}Unexpected number in JSON at position 8
Line break inside a stringa string with a real line breakBad control character in string literal in JSON at position 15
Two root values{"a":1}{"b":2}Unexpected non-whitespace character after JSON at position 7
Empty input(nothing)Unexpected end of JSON input
Smart quotes{“name”: “Ana”}Expected property name or '}' in JSON at position 1

Newer V8 versions also add the line and column, for example "(line 1 column 27)".

How to read "at position N"

Position counts characters from zero, starting at the very first character of the input. Position 26 in {"name": "Ana", "age": 30,} is the closing }: the parser saw the comma, expected another key, and found the end of the object instead. So the character at the reported position is often after the real mistake. Look just before it.

Fixes for each error

  • Trailing comma: delete the comma after the last item in an object or array.
  • Single quotes or unquoted keys: put every key and every string in double quotes. {"name": "Ana"}
  • Missing comma: add a comma between items. Missing commas usually happen when lines are copied from different places.
  • Comments: remove them. JSON has no comment syntax. If you need notes, add a regular field such as "_note": "...".
  • Unclosed braces or brackets: every { needs a } and every [ a ]. Formatting the text with indentation makes a missing one easy to spot.
  • NaN, Infinity, undefined: not allowed. Use null, or a number, or a string.
  • Leading zeros: write 7, or a string "007" if the zeros matter, as with IDs and postcodes.
  • Line breaks and tabs in strings: escape them as \n and \t.
  • Two root values: a JSON document has exactly one top-level value. Wrap several objects in an array: [{"a":1},{"b":2}]. (Files with one object per line are "JSON Lines", a different format.)
  • Empty input: the request or file was empty. Check that the data actually arrived, for example that an API returned a body.
  • Smart quotes: word processors and chat apps turn " into “ and ”. Paste code through a plain text editor, or retype the quotes.

"Unexpected token <" when calling an API

If the message mentions <, such as Unexpected token '<', "<!DOCTYPE "... is not valid JSON, you didn't receive JSON at all. The server sent an HTML page, usually an error page, a login redirect or a 404. Check the URL, the status code and the response body before looking at your parsing code.

A quick way to find the problem

  1. Paste the text into the JSON Formatter and select Validate.
  2. If it's invalid, look at the reported position and the character just before it.
  3. If it's valid, select Format with 2 spaces, 4 spaces or tabs to read the structure, or Minify to compact it.

The formatter doesn't repair or reorder your data, so what you see is exactly what you pasted. It runs in your browser, which matters when the JSON contains API keys or personal data.

Valid JSON checklist

  • Keys and strings in double quotes
  • Commas between items, none after the last
  • Values only: string, number, true, false, null, object, array
  • No comments, no functions, no dates as objects (use ISO strings like "2026-09-30")
  • One top-level value
  • UTF-8 text

Frequently asked questions

Can JSON have comments?

No. Standard JSON has no comments. Some config formats such as JSONC or JSON5 allow them, but a normal JSON parser will reject them.

Is a trailing comma allowed in JSON?

No. JavaScript accepts trailing commas in objects and arrays, but JSON does not.

Why does my JSON work in JavaScript but fail in JSON.parse?

JavaScript object syntax is more relaxed: it allows single quotes, unquoted keys, comments and trailing commas. JSON allows none of them.

What does "Unexpected end of JSON input" mean?

The text ended before the JSON was complete, or was empty. Often an API returned an empty response.

Related

Sources