The exact wording of a JSON error depends on the browser, the Node.js version or the programming language. Where the message changed between versions, both forms are shown below. If you cannot find your message, look at the cause that matches your situation.
Quick list
- Unexpected token < in JSON at position 0
- Unexpected end of JSON input
- [object Object] is not valid JSON
- "undefined" is not valid JSON
- Trailing comma errors
- Single quotes and unquoted keys
- Missing comma
- Extra data after the JSON
- Bad control character in a string
- Comments, True, None and NaN
Unexpected token < in JSON at position 0
Newer wording: Unexpected token '<', "<!DOCTYPE "... is not valid JSON. Python: Expecting value: line 1 column 1 (char 0).
Cause: The text you tried to parse is not JSON at all. It starts with a <, which usually means the server sent back an HTML page, such as a 404 page, a login page or an error page, instead of JSON.
Fix: Look at what the response really contains before you parse it, and check the status code and the address you called.
const res = await fetch(url);
if (!res.ok) throw new Error('HTTP ' + res.status);
const text = await res.text();
console.log(text.slice(0, 200)); // is this HTML?
const data = JSON.parse(text);
Unexpected end of JSON input
Python: Expecting value: line 1 column 1 (char 0) for empty text, or Unterminated string starting at.
Cause: The text is empty, or it stops before the JSON is finished. Typical reasons are an empty response body (for example a 204 status), a cut-off download, or a copy that missed the last bracket.
Fix: Check that the text is not empty before parsing. If it was cut off, get the full text again. If you only have the cut-off copy, the JSON Repair tool can close the missing brackets and braces when the text stops after a complete value.
[object Object] is not valid JSON
Older wording: Unexpected token o in JSON at position 1.
Cause: You passed an object to JSON.parse. JavaScript turns the object into the text "[object Object]" first, and that text is not JSON. The data was probably already parsed, for example by response.json() or by an HTTP library.
Fix: Do not parse it a second time. If you need JSON text from an object, use JSON.stringify(obj).
"undefined" is not valid JSON
Older wording: Unexpected token u in JSON at position 0.
Cause: The value you parsed is undefined. A property name may be wrong, a request may not have finished, or a value was never set.
Fix: Check the variable before you parse it.
if (typeof raw === 'string' && raw.length) {
const data = JSON.parse(raw);
}
Trailing comma errors
Messages: Unexpected token } in JSON at position N, Expected double-quoted property name in JSON at position N. Python: Expecting property name enclosed in double quotes.
Cause: A comma after the last item of an object or array. JavaScript allows this in code, but JSON does not.
{"a": 1, "b": 2,} // invalid
{"a": 1, "b": 2} // valid
Fix: Remove the last comma. The JSON Repair tool does this for you.
Single quotes and unquoted keys
Messages: Unexpected token ' in JSON at position 1, Expected property name or '}' in JSON at position 1. Python: Expecting property name enclosed in double quotes.
Cause: JSON only accepts double quotes, and every key must be in quotes. Single quotes and keys without quotes work in JavaScript and Python code but are not valid JSON.
{'name': 'Ali'} // invalid
{name: "Ali"} // invalid
{"name": "Ali"} // valid
Fix: Use double quotes for all keys and string values.
Missing comma
Messages: Expected ',' or '}' after property value in JSON at position N. Python: Expecting ',' delimiter: line L column C.
Cause: Two items follow each other without a comma between them, which often happens after editing a file by hand.
Fix: Add the comma at the position the message points to, usually right after the previous value. The position is counted in characters from the start of the text.
Extra data after the JSON
Messages: Unexpected non-whitespace character after JSON at position N. Python: Extra data: line L column C.
Cause: The text contains one complete JSON value followed by more text. This happens with two JSON objects pasted one after another, with files in JSON Lines format (one JSON value per line), or with a sentence after the JSON in an AI reply.
Fix: Parse one value at a time. For JSON Lines, split the text into lines and parse each line separately. To break a large JSON array into smaller files, use the JSON Splitter.
Bad control character in a string
Message: Bad control character in string literal in JSON at position N. Python: Invalid control character at: line L column C.
Cause: A string contains a real line break or tab. In JSON these must be written as \n and \t.
Fix: Replace the line break with \n. The JSON Escape tool escapes text for you, and quotes inside strings must be written as \".
Comments, True, None and NaN
Cause: JSON has no comments, and its only literal values are true, false and null. Text copied from JavaScript or Python often contains // comments, True, False, None, undefined or NaN, and parsers reject all of them. The message depends on where the parser first gets stuck.
Fix: Remove the comments and use true, false and null. In Python, json.dumps() writes the correct form for you.
Frequently asked questions
What does "position N" mean in a JSON error?
It is the number of characters from the start of the text to the place where parsing failed. The real mistake is often just before that position, for example a missing comma after the previous value.
Why is my JSON valid in JavaScript code but rejected by JSON.parse?
JavaScript object literals allow single quotes, keys without quotes, comments and trailing commas. JSON is a stricter format and allows none of them.
How can I find the exact line of an error?
Paste the text into the JSON Formatter, which reports where the syntax error is. For a quick automatic fix, try the JSON Repair tool.
Is my JSON uploaded when I use these tools?
No. The tools run in your browser with JavaScript, and nothing you paste is sent to a server.
Related tools
Fix broken JSON with the JSON Repair tool. Check syntax with the JSON Formatter. Escape strings with JSON Escape and Unescape. Compare two versions with JSON Diff.