Open huge JSON files instantly. Free & private.๐Ÿ”’ Your data never leaves your browser

Unexpected Token in JSON: What It Means and How to Fix It

SyntaxError: Unexpected token is the most common JSON error in JavaScript. It means JSON.parse() (or response.json()) found a character it did not expect at a certain position. The good news: the exact wording of the message usually tells you the cause. This guide goes through the variants you are most likely to see.

First, find the exact position

Most messages include a position, like at position 52 or (line 3 column 5). Paste the text into the JSON Validator and it highlights the exact line and column, with a plain-English explanation of what is wrong.

Try it: JSON ValidatorPaste your JSON and jump straight to the error.
Open JSON Validator โ†’

"Unexpected token < in JSON at position 0"

This is the classic one. The very first character is <, which means you received HTML, not JSON. Usually the server returned an error page or a login page instead of the API response:

<!DOCTYPE html>
<html><head><title>404 Not Found</title>...

Typical causes:

  • Wrong URL or a typo in the API path (the server returns its 404 page)
  • The server crashed and returned a 500 error page
  • You are not logged in, so you were redirected to a login page
  • In development, the request went to your front-end dev server, which returns index.html for unknown paths

Check the response before parsing it:

const res = await fetch('/api/orders')
if (!res.ok) {
  throw new Error(`HTTP ${res.status}: ${await res.text()}`)
}
const data = await res.json()

Opening the request in your browser's developer tools (Network tab) also shows you what the server actually sent.

"Unexpected end of JSON input"

The text ended before the JSON was complete. Common causes:

  • Empty response. The server returned nothing (for example a 204 No Content), and you called .json() on it.
  • Truncated data. A download or log file was cut off, so closing brackets are missing.
  • Parsing an empty string from storage, such as JSON.parse(localStorage.getItem('x') || '').

For truncated data, JSON Repair can add the missing closing brackets so you can still read what was received.

"Unexpected token u in JSON at position 0"

The text starts with u, almost always from the word undefined. You called JSON.parse(undefined): the variable you passed was never set. Check where the value comes from before parsing it.

"Unexpected token o in JSON at position 1"

You passed an object, not a string. JavaScript converts it to the text [object Object], and the parser fails at the o. The data is already parsed, so you can use it directly without calling JSON.parse again.

"Unexpected token ' in JSON" or "Expected property name"

JSON only allows double quotes. Single quotes and unquoted keys are valid JavaScript, but not valid JSON:

{ 'name': 'Ann' }     โœ— single quotes
{ name: "Ann" }       โœ— unquoted key
{ "name": "Ann" }     โœ“ valid JSON

"Unexpected token }" or "]"

Usually a trailing comma: a comma after the last item, right before a closing bracket. JSON does not allow it, even though JavaScript does.

{ "a": 1, "b": 2, }   โœ—
{ "a": 1, "b": 2 }    โœ“

Python: "JSONDecodeError: Expecting value"

Python reports the same problems with different words. Expecting value: line 1 column 1 (char 0) usually means an empty string or an HTML page. Expecting property name enclosed in double quotes means single quotes, an unquoted key or a trailing comma.

๐Ÿ’ก If you control the code that creates the JSON, never build it by joining strings. Use JSON.stringify() in JavaScript or json.dumps() in Python, and the output will always be valid.

Quick reference

Message containsMost likely cause
< at position 0Got an HTML page (404, 500 or login)
end of JSON inputEmpty or truncated response
u at position 0Parsing undefined
o at position 1Parsing an object that is already parsed
' or property nameSingle quotes or unquoted keys
} or ]Trailing comma

For a longer list with examples, see 9 common JSON syntax errors.

Tools used in this guide

More guides