What JSON Error Messages Mean
JSON error messages are short and written for parsers, not people. Once you know how to read them, though, each one tells you exactly what the parser expected, what it found instead, and where. This guide translates the messages you'll meet most often in browsers, Node.js and Python.
The exact wording depends on which JavaScript engine or language is parsing the JSON. The examples here were produced with Node.js 22 (the same V8 engine as Chrome and Edge) and Python 3, so you can match them character for character. Firefox and Safari word things differently, but the causes are the same.
How to read any JSON error
Take this message from Chrome or Node:
SyntaxError: Expected ',' or '}' after property value in JSON at position 20 (line 3 column 3)It has three parts:
- SyntaxError: the text isn't valid JSON. (A
TypeErrormeans something else, usually that you passed a value that isn't a string.) - What it expected: here, a comma or a closing brace after a value. That's the parser telling you the item before this point is complete and something has to separate it from what comes next.
- Where: position 20 counts characters from the start, beginning at 0. line 3 column 3 is the same spot in a form people can find. Python gives both too: line 3 column 3 (char 20).
Remember that the position is where the parser noticed the problem. For a missing comma that's the start of the next item, often on the line below the real mistake.
Unexpected token '<', "<!DOCTYPE "... is not valid JSON
This is probably the most-searched JSON error, and the JSON is almost never the problem. Your code asked for JSON, but the server sent back an HTML page. HTML starts with <!DOCTYPE html> or <html>, and < can't start any JSON value, so parsing fails on the first character.
const response = await fetch("/api/users");
const users = await response.json(); // SyntaxError: Unexpected token '<'Common reasons the server returned HTML instead of JSON:
- Wrong URL. A typo or a missing
/apiprefix gets you the site's 404 page. Single-page apps often answer every unknown path withindex.html. - Server error. The backend crashed and returned an HTML error page with status 500.
- Not logged in. The request was redirected to a login page.
- Development proxy not set up, so requests reach the front-end dev server instead of your API.
To find out which, open your browser's developer tools, go to the Network tab, click the request, and look at its status code and response body. In code, check the status and content type before parsing, so the error tells you what actually happened:
const response = await fetch("/api/users");
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
const type = response.headers.get("content-type") || "";
if (!type.includes("application/json")) {
const text = await response.text();
throw new Error(`Expected JSON but got: ${text.slice(0, 100)}`);
}
const users = await response.json();Unexpected end of JSON input
The parser reached the end of the text while it was still expecting more. There are two very different causes:
- The text is empty.
JSON.parse("")throws this error. Withfetch, it usually means the response had no body, for example a204 No Contentreply to a DELETE request, or an error response with nothing in it. Checkresponse.statusbefore callingresponse.json(). - The JSON was cut off. A closing bracket or quote is missing because the text was truncated: a partial copy, a log line that hit a length limit, or a download that was interrupted. See missing brackets.
Python reports an empty string as Expecting value: line 1 column 1 (char 0), the same message it gives for HTML or any other text that doesn't start like JSON.
"[object Object]" is not valid JSON
You called JSON.parse() on something that was already a JavaScript object. JSON.parse converts its argument to a string first, and a plain object becomes the text [object Object], which isn't JSON.
const data = await response.json(); // already parsed into an object
JSON.parse(data); // SyntaxError: "[object Object]" is not valid JSONThe fix is to remove the extra parse. response.json() in fetch, Axios's response.data, and most HTTP libraries already give you parsed objects. If you're not sure what you have, log typeof data: you only need JSON.parse when it says "string".
"undefined" is not valid JSON
JSON.parse(undefined) turns undefined into the text "undefined" and fails on it. The value you meant to parse doesn't exist yet: a misspelled property, a variable that was never assigned, or a function that didn't return anything. Log the value right before parsing to see what you actually have.
A quirk worth knowing
JSON.parse(null) doesn't throw. It returns null, because null becomes the text "null", which is valid JSON. That's why reading a missing key with JSON.parse(localStorage.getItem("settings")) gives you null rather than an error, and the crash happens later when you try to use it.
Messages caused by typos in the JSON
These messages mean the text really is meant to be JSON but breaks a rule. Each links to the fix in common JSON errors.
| Chrome / Node message | Usual cause |
|---|---|
| Expected double-quoted property name | A trailing comma before } |
| Unexpected token ']' | A trailing comma before ] |
| Expected property name or '}' | A key in single quotes, without quotes, or a comment |
| Expected ',' or '}' after property value | A missing comma between items, or a missing closing brace |
| Unexpected token 'u' / 'N' / 'T' | undefined, NaN or True, which JSON doesn't allow |
| Unexpected number | A number with a leading zero, like 012 |
| Bad control character in string literal | A real line break or tab inside a string; escape it as \n or \t |
| Bad escaped character | A backslash before a letter that isn't an escape, often a Windows path |
| Unterminated string | A string that's missing its closing quote |
| Unexpected non-whitespace character after JSON | Something after the end of the JSON, like an extra closing bracket or two JSON documents pasted together |
Python's JSONDecodeError messages
Python's json module raises json.JSONDecodeError (a subclass of ValueError). Its messages say what the parser was expecting:
| Python message | Usual cause |
|---|---|
| Expecting value: line 1 column 1 (char 0) | Empty text, HTML, or anything else that isn't JSON at all |
| Expecting property name enclosed in double quotes | Single-quoted or unquoted key, or a trailing comma (before Python 3.13) |
| Illegal trailing comma before end of object | A trailing comma (Python 3.13 and later name it directly) |
| Expecting ',' delimiter | A missing comma, or a missing closing bracket |
| Extra data | More text after a complete JSON value |
| Invalid control character at | A real line break or tab inside a string |
| Unterminated string starting at | A string without its closing quote |
| Unexpected UTF-8 BOM (decode using utf-8-sig) | The file starts with an invisible byte-order mark, common in files saved by Windows tools. Open it with encoding="utf-8-sig" |
One difference to watch for: by default Python accepts NaN and Infinity when reading JSON, and writes them when saving it, even though they aren't valid JSON. A file Python reads happily can then fail in JavaScript. The Python guide shows how to switch that off.
Firefox and Safari
Firefox prefixes its messages with JSON.parse: and gives a line and column, for example JSON.parse: unexpected character at line 1 column 1 of the JSON data or JSON.parse: expected ',' or '}' after property value in object. Safari's messages start with JSON Parse error: and often leave the position out, as in JSON Parse error: Unrecognized token '<'. The wording changes between versions, so match on the meaning rather than the exact text. When a message doesn't include a position, paste the JSON into the JSON tool to see the line and column marked.