Skip to content

How to Fix "Unexpected token" Errors in JSON

Updated

SyntaxError: Unexpected token ... in JSON at position ... is the most common JSON error in existence. It means the parser hit a character that is illegal at that point in the document. The token named in the message tells you which of a handful of well-known mistakes you're looking at.

Paste your JSON into the free validator to get the exact line and column, then match the token below.

Unexpected token ' — single quotes

JSON requires double quotes around every string and every key. Single quotes are valid in JavaScript, Python, and most languages' string literals, which is exactly why this mistake is so common — the data looks right everywhere except to a JSON parser.

Invalid
{'name': 'Ada'}
Valid
{"name": "Ada"}

Unexpected token } or ] — trailing comma

A comma after the last item in an object or array is legal in modern JavaScript but forbidden in JSON. The parser reads the comma, expects another item, and instead finds the closing brace or bracket — hence the "unexpected" token.

Invalid
{"a": 1, "b": 2,}
Valid
{"a": 1, "b": 2}

Unexpected token / — comments

JSON has no comment syntax. Neither // line comments nor /* block comments */ are allowed anywhere in a document. If you control the file, move the commentary into documentation or code; if the format must support comments, you are looking for JSONC or JSON5, not JSON.

Invalid
{
  // API settings
  "timeout": 30
}
Valid
{
  "timeout": 30
}

Unexpected token at position 0 — not JSON at all

An error at position 0 usually means the string you parsed isn't JSON: an HTML error page returned by an API (Unexpected token <), an empty response, or a value like undefined. Log the raw string before parsing — the problem is what the server sent, not your parser.

Related: unquoted keys ({name: "Ada"}) and JavaScript-only values (undefined, NaN, Infinity) also throw unexpected-token errors — both are legal in JS object literals but not in JSON.

The fastest way to find the broken character

"Position 1478" is useless in a minified one-line document. Paste the payload into the validator: it reports the failure as a line and column, and after you fix and beautify, any remaining structural issues become obvious in the indentation.

Try it now

Paste your JSON into the free toolkit — validate, beautify, minify, and explore it without your data ever leaving the browser.

Open the JSON Toolkit

Frequently asked questions

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

The very first character is already illegal — the string is usually not JSON at all. Common culprits: an HTML error page (starts with <), an empty string, or the literal text undefined. Inspect the raw response before parsing.

Why is my JSON invalid when JavaScript accepts it?

JavaScript object literals allow single quotes, unquoted keys, trailing commas, and comments. JSON (RFC 8259) forbids all four. JSON.parse applies the stricter JSON rules even inside JavaScript.

How do I find which character is causing the error?

Paste the JSON into a validator that reports line and column, such as the Advanced JSON Toolkit. It pinpoints the first offending character instantly, entirely in your browser.