Common JSON syntax errors: what each message means and how to fix it

By Hammad Rasool · November 11, 2026

Quick answer: almost every JSON syntax error comes from one of five habits carried over from JavaScript or Python: a trailing comma, single quotes, unquoted keys, comments, or a value such as NaN, undefined or True that JSON doesn't have. The error message tells you where the parser gave up, which is often one line after the real mistake. Paste the text into the JSON formatter to see the message with a line and column, then use the table below to find the fix.

How this was tested: on 11 November 2026, 28 broken and borderline JSON snippets were parsed with JSON.parse in Chrome 156 and Node.js 24.18.1 (both use the V8 engine and gave identical messages) and with json.loads in Python 3.12.2. Every error message on this page is copied from those runs. Firefox and Safari were not tested; their messages are worded differently.

JSON error messages and what they mean

Chrome / Node.js messagePython messageUsual cause
Expected double-quoted property nameExpecting property name enclosed in double quotesTrailing comma before }
Expected property name or '}'Expecting property name enclosed in double quotesSingle-quoted or unquoted key, smart quotes, a comment
Expected ',' or '}' after property valueExpecting ',' delimiterMissing comma, comment after a value, hex number
Expected ',' or ']' after array elementExpecting ',' delimiterWrong or missing closing bracket
Unexpected token ']'Expecting valueTrailing comma in an array
Unexpected token 'N' / 'I' / 'u' / 'T'Expecting value (or accepted, see below)NaN, Infinity, undefined, Python's True/None
Unexpected token '<', "<!DOCTYPE "... is not valid JSONExpecting value: line 1 column 1The server sent an HTML page, not JSON
Bad control character in string literalInvalid control character atA real line break or tab inside a string
Bad escaped characterInvalid \escapeA single backslash, often in a Windows path
Unexpected numberExpecting ',' delimiterA leading zero such as 04501
Unexpected end of JSON inputExpecting value: line 1 column 1 (char 0)Empty string, or a response with no body
Unexpected non-whitespace character after JSONExtra dataTwo JSON documents in one string (NDJSON)
"[object Object]" is not valid JSON(not applicable)Passing an object that is already parsed to JSON.parse
Unexpected token ''Unexpected UTF-8 BOM (decode using utf-8-sig)A byte order mark at the start of the file

Read the position, then look one step back

A parser reports the first character it can't accept, not the character you got wrong. Two examples from the test:

{
  "name": "Sara",
  "age": 31,
}

Chrome: Expected double-quoted property name in JSON at position 33 (line 4 column 1). Line 4 is the closing brace. The mistake is the comma at the end of line 3: after a comma the parser expects another key, and finds } instead.

{
  "name": "Sara"
  "age": 31
}

Chrome: Expected ',' or '}' after property value in JSON at position 21 (line 3 column 3). Python: Expecting ',' delimiter: line 3 column 3 (char 21). Both point at "age"; the comma is missing at the end of line 2.

Positions count characters from zero, and Python's column counts from one, so char 21 and column 3 are the same place. Some Chrome messages, such as Unexpected token 'N', give no position at all and quote the start of the text instead.

1. Trailing commas

JavaScript allows [1, 2, 3,]; JSON doesn't. In an array Chrome says Unexpected token ']', "[1, 2, 3,]" is not valid JSON and Python says Expecting value: line 1 column 10 (char 9). In an object, see the example above. Fix: delete the last comma before ] or }.

2. Single quotes, unquoted keys and smart quotes

{'name': 'Sara'}, {name: "Sara"} and {“name”: “Sara”} all failed at the same place with the same message: Expected property name or '}' in JSON at position 1 (line 1 column 2). JSON keys and strings need straight double quotes. Curly quotes usually arrive when JSON is pasted through Word, Google Docs, Slack or a phone keyboard. Fix: replace every quote with " and quote every key.

3. Comments

Standard JSON has no comments. A // line failed with Expected property name or '}', and a /* */ block after a value failed with Expected ',' or '}' after property value. Some files that look like JSON accept comments because their own tools parse them more loosely (VS Code calls this "JSON with Comments"), but JSON.parse and json.loads do not. Fix: remove the comments, or move the note into a field such as "_comment".

4. Missing commas and brackets

{"items": [1, 2, 3} gave Expected ',' or ']' after array element in JSON at position 18: the array was never closed. A cut-off file such as {"items": [1, 2 gave the same message at the end of the text. If the position is the last character, the file is probably truncated: check the download or the log line length limit before hunting for a typo. Fix: format the text; mismatched brackets show up as indentation that never comes back to the left edge.

5. Values JSON doesn't have

JSON has exactly six kinds of value: string, number, object, array, true/false and null. These all failed in Chrome:

  • NaN and Infinity: Unexpected token 'N', Unexpected token 'I'
  • undefined: Unexpected token 'u'
  • Python's True and None: Unexpected token 'T'

Fix: write null, true and false in lower case. Use null for a missing number. When JavaScript creates the JSON, JSON.stringify already does this: it wrote {a: NaN, b: Infinity, c: undefined, d: [undefined]} as {"a":null,"b":null,"d":[null]}, dropping the undefined property.

Python writes JSON that JavaScript can't read

This is the least-known problem on the list. Python's json module accepts NaN and Infinity by default and also writes them, so a Python service can produce a response that every browser rejects:

>>> json.loads('{"score": NaN}')
{'score': nan}                          # accepted, although it is not JSON

>>> json.dumps({"score": float("nan")})
'{"score": NaN}'                        # JavaScript's JSON.parse rejects this

>>> json.dumps({"score": float("nan")}, allow_nan=False)
ValueError: Out of range float values are not JSON compliant: nan

Pass allow_nan=False to json.dumps to catch it at the source. The other common Python mistake is sending str(data) instead of json.dumps(data):

>>> str({"active": True, "manager": None})
"{'active': True, 'manager': None}"     # Python syntax, not JSON

>>> json.dumps({"active": True, "manager": None})
'{"active": true, "manager": null}'     # JSON

If you've been handed text in Python's format, ast.literal_eval reads it back safely and json.dumps turns it into real JSON. In the test that produced {"active": true, "manager": null, "name": "Sara"}.

6. Line breaks, tabs and backslashes inside strings

A real line break inside a string gave Bad control character in string literal in JSON at position 18 (Python: Invalid control character at). A real tab gave the same error. JSON strings must write them as \n and \t. This usually happens when JSON is assembled by string concatenation instead of a serializer.

A Windows path is the classic backslash error:

{"path": "C:\Users\sara"}

Chrome: Bad escaped character in JSON at position 13. Python: Invalid \escape: line 1 column 13 (char 12). \U isn't a JSON escape. Only \" \\ \/ \b \f \n \r \t and \uXXXX are. Note that a path such as C:\temp would not fail, because \t is valid: it silently becomes a tab. Fix: double every backslash, or use forward slashes:

{"path": "C:\\Users\\sara"}

Better still, build the JSON with JSON.stringify or json.dumps. Python's json.dumps turned the path into the escaped form above in the test.

7. Numbers: leading zeros, plus signs, hex and .5

04501 gave Unexpected number in JSON at position 9. +1 and .5 gave Unexpected token '+' and Unexpected token '.', and 0x1F failed as a missing comma. JSON numbers can't start with +, a decimal point or a leading zero, and there is no hex. Fix: write 0.5, 1 and 31. Store zip codes, phone numbers and account numbers as strings ("04501"), or the zero is lost anyway.

8. "Unexpected token <": you got HTML, not JSON

Unexpected token '<', "<!DOCTYPE "... is not valid JSON means the text starts with <. The JSON itself is fine; the request returned an HTML page instead, such as a 404 page, a login redirect, a 502 from a proxy or a development server's fallback page. The same goes for Unexpected end of JSON input, which is what an empty response body produces. Fix: check the status and the content type before parsing, so the real problem shows up in the error:

const res = await fetch("/api/users");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const type = res.headers.get("content-type") || "";
if (!type.includes("application/json")) {
  throw new Error("Expected JSON, got " + type);
}
const data = await res.json();

9. A byte order mark at the start of the file

Some Windows editors save UTF-8 with an invisible byte order mark (BOM, U+FEFF). Chrome reported Unexpected token '', which looks like an error about nothing because the character is invisible. Python is clearer: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0). RFC 8259 says programs must not add a BOM to JSON they send. Fix: save the file as UTF-8 without BOM, open it in Python with encoding="utf-8-sig", or strip it in JavaScript with text.replace(/^\uFEFF/, ""). All three worked in the test.

10. Two documents in one string, and parsing twice

Log files and exports often hold one JSON object per line (NDJSON or JSON Lines). Parsing the whole file at once gave Unexpected non-whitespace character after JSON at position 9 (line 2 column 1) in Chrome and Extra data in Python. Parse it line by line:

const rows = text
  .split("\n")
  .filter((line) => line.trim() !== "")
  .map((line) => JSON.parse(line));

"[object Object]" is not valid JSON means JSON.parse was given an object, not text. JavaScript turns the object into the string [object Object] first. The data is usually already parsed: res.json(), axios and most frameworks parse the response for you, so remove the extra JSON.parse.

Valid JSON that still causes bugs

These parsed without any error, which is exactly why they are easy to miss:

  • Duplicate keys. {"a": 1, "a": 2} parsed as {"a": 2} in Chrome, Node.js and Python: the last value wins, with no warning. RFC 8259 says names should be unique and that other parsers may behave differently.
  • Big integers. {"id": 9007199254740993} came back from JSON.parse as 9007199254740992, because JavaScript numbers lose precision above 253. Python kept the exact value. Send large IDs as strings, or read the original digits with a reviver. The context.source argument used below worked in Node.js 24; check support in the browsers you target before relying on it.
const text = '{"id": 9007199254740993}';

JSON.parse(text).id;            // 9007199254740992  (last digit changed)

JSON.parse(text, (key, value, context) =>
  typeof value === "number" && !Number.isSafeInteger(value)
    ? BigInt(context.source)
    : value
).id;                           // 9007199254740993n

How to find the error quickly

  1. Paste the text into the JSON formatter. It runs JSON.parse in your browser and shows the same message as above, with the line and column for most errors.
  2. Go to that line, then look at the end of the line before it for a missing or extra comma.
  3. If the message names a character ('N', 'u', '<'), search for it: it's a value JSON doesn't allow, or HTML.
  4. If the file is YAML that someone called JSON, convert it with the YAML to JSON converter instead of fixing it by hand.

FAQ

What does "Unexpected token in JSON at position 0" mean?

The very first character is wrong, so the text isn't JSON at all. It's usually HTML (an error page), a byte order mark, or a plain-text error message from the server. Log the raw text before parsing it.

Does JSON allow comments or trailing commas?

No. RFC 8259 and ECMA-404 allow neither. Formats such as JSON5 and VS Code's JSON with Comments do, but a standard parser rejects them.

Can JSON use single quotes?

No. Keys and strings must use double quotes. A single quote may appear inside a string as an ordinary character.

Why does the error point to the wrong line?

The parser reports where it noticed the problem. A missing comma at the end of line 2 is noticed at the start of line 3, and a trailing comma on line 3 is noticed at the closing brace on line 4.

How do I put a line break in a JSON string?

Write \n inside the string. A real line break between the quotes is an error.

Is my data sent anywhere when I use the formatter?

No. The JSON formatter runs in your browser; nothing is uploaded.

Sources