JSON parse errors: what each message means and how to fix it
A JSON error message tells you where the parser stopped, not always why. This checklist puts the messages JavaScript (Chrome, Edge and Node.js) and Python give for the same 16 broken texts side by side, with the usual cause and the fix. Every message was produced by running the text through JSON.parse in Node.js 24.14 and json.loads in Python 3.14.7, not copied from elsewhere.
Find your error message
Search this page for the first words of your message (Ctrl+F or Cmd+F). Positions differ with your text; the wording does not. Firefox and Safari word the same errors differently; Firefox's list is on MDN's JSON.parse: bad parsing page.
| Error | JavaScript (JSON.parse) | Python (json.loads) |
|---|---|---|
| Unexpected end of JSON input (empty text) | Unexpected end of JSON input | Expecting value: line 1 column 1 (char 0) |
| Unexpected token '<' (an HTML page instead of JSON) | Unexpected token '<', "<!DOCTYPE "... is not valid JSON | Expecting value: line 1 column 1 (char 0) |
| "undefined" is not valid JSON | "undefined" is not valid JSON | Expecting value: line 1 column 1 (char 0) |
| "[object Object]" is not valid JSON | "[object Object]" is not valid JSON | Expecting value: line 1 column 2 (char 1) |
| Trailing comma | Expected double-quoted property name in JSON at position 16 (line 1 column 17) | Illegal trailing comma before end of object: line 1 column 16 (char 15) |
| Missing comma | Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9) | Expecting ',' delimiter: line 1 column 9 (char 8) |
| Single quotes | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
| Unquoted key | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
| Python None, True or False | Unexpected token 'N', "{"a": None}" is not valid JSON | Expecting value: line 1 column 7 (char 6) |
| NaN or Infinity | Unexpected token 'N', "{"a": NaN}" is not valid JSON | accepted |
| Cut-off document | Expected ',' or ']' after array element in JSON at position 11 (line 1 column 12) | Expecting ',' delimiter: line 1 column 12 (char 11) |
| Unterminated string | Unterminated string in JSON at position 9 (line 1 column 10) | Unterminated string starting at: line 1 column 7 (char 6) |
| Line break or tab inside a string | Bad control character in string literal in JSON at position 11 (line 1 column 12) | Invalid control character at: line 1 column 12 (char 11) |
| Number with a leading zero | Unexpected number in JSON at position 7 (line 1 column 8) | Expecting ',' delimiter: line 1 column 8 (char 7) |
| Text after the end (two documents, a comment) | Unexpected non-whitespace character after JSON at position 9 (line 1 column 10) | Extra data: line 1 column 10 (char 9) |
| Invisible byte order mark (BOM) at the start | Unexpected token '', "{"a": 1}" is not valid JSON | Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0) |
Each error: cause and fix
For each text: what JavaScript, Python and JSON Editor Free's status bar say, why it happens, how to fix it at the source, and what JSON repair in the editor turns it into.
Unexpected end of JSON input (empty text)
- Text
- (an empty string)
- JavaScript says
SyntaxError: Unexpected end of JSON input- Python says
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)- JSON Editor Free says
- Unexpected end of the document: expected a value
- Cause
- The parser got nothing to read. Most often this is a fetch() response with no body: a 204 No Content, an error status with an empty body, or a request that failed before any data came back. A file that was created but never written gives the same error.
- Fix
- Check the status before parsing and read the body as text first, so you can see what arrived. Parse only when the text is not empty. If a JSON document was cut off part-way, see "Cut-off document" below.
- Repair
- not the fix here: the text is not broken JSON, so fix where it came from
Unexpected token '<' (an HTML page instead of JSON)
- Text
<!DOCTYPE html><html>- JavaScript says
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON- Python says
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)- JSON Editor Free says
- Expected a value but found "<"
- Cause
- The server sent a web page, not JSON: a 404 page, a login redirect, a proxy or gateway error, or a development server answering a wrong API path with its index.html. The < is the first character of <!DOCTYPE html>. Older versions of Chrome and Node.js word it as "Unexpected token < in JSON at position 0".
- Fix
- Log the status, the Content-Type header and the first 200 characters of the body. Fix the request URL, the sign-in or the server error; the JSON was never there to parse.
- Repair
- not the fix here: the text is not broken JSON, so fix where it came from
"undefined" is not valid JSON
- Text
undefined- JavaScript says
SyntaxError: "undefined" is not valid JSON- Python says
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)- JSON Editor Free says
- Expected a value but found "u"
- Cause
- JSON.parse(undefined) turns undefined into the text "undefined" and fails on it. The variable, property or message field you parsed was never set. (A missing localStorage key is different: getItem returns null, and JSON.parse(null) returns null without an error.)
- Fix
- Check that the value exists before you parse it, and find out why it is missing: a wrong property name, a response that has not arrived yet, or a key that was never saved.
- Repair
- not the fix here: the text is not broken JSON, so fix where it came from
"[object Object]" is not valid JSON
- Text
[object Object]- JavaScript says
SyntaxError: "[object Object]" is not valid JSON- Python says
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)- JSON Editor Free says
- Expected a value but found "o"
- Cause
- An object was turned into text without JSON.stringify: String(value), a template string, or localStorage.setItem(key, value), which all store "[object Object]". It also happens when you parse a value that is already an object, for example the result of response.json().
- Fix
- Save objects with JSON.stringify(value) and parse them with JSON.parse(text). Do not parse what response.json() returns; it is already parsed.
- Repair
- not the fix here: the text is not broken JSON, so fix where it came from
Trailing comma
- Text
{"a": 1, "b": 2,}- JavaScript says
SyntaxError: Expected double-quoted property name in JSON at position 16 (line 1 column 17)- Python says
json.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 1 column 16 (char 15)- JSON Editor Free says
- Trailing comma: remove the comma before }
- Cause
- A comma after the last item. JavaScript code allows it; JSON does not. JavaScript expects another key after the comma, so it points at the } and asks for a property name; Python points at the comma itself.
- Fix
- Delete the comma before the closing } or ].
- Repair
- returns
{"a": 1, "b": 2}
Missing comma
- Text
{"a": 1 "b": 2}- JavaScript says
SyntaxError: Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9)- Python says
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 9 (char 8)- JSON Editor Free says
- Expected a comma or a closing brace } but found "\""
- Cause
- Two items with nothing between them, often after lines were pasted together or one was deleted.
- Fix
- Add a comma between the items at the position the message gives.
- Repair
- returns
{"a": 1, "b": 2}
Single quotes
- Text
{'a': 'x'}- JavaScript says
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)- Python says
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)- JSON Editor Free says
- Expected a property name in double quotes: strings and keys need double quotes, not single quotes
- Cause
- JSON strings and keys need double quotes. Single quotes come from text written by hand, from JavaScript code, or from printing a Python dict, which uses 'single' quotes.
- Fix
- Use double quotes. In Python, write JSON with json.dumps(data) instead of str(data) or print(data).
- Repair
- returns
{"a": "x"}
Unquoted key
- Text
{a: 1}- JavaScript says
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)- Python says
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)- JSON Editor Free says
- Expected a property name in double quotes but found "a"
- Cause
- A JavaScript object literal was copied as JSON. In JSON every key is a string in double quotes.
- Fix
- Put double quotes around every key, or produce the text with JSON.stringify.
- Repair
- returns
{"a": 1}
Python None, True or False
- Text
{"a": None}- JavaScript says
SyntaxError: Unexpected token 'N', "{"a": None}" is not valid JSON- Python says
json.decoder.JSONDecodeError: Expecting value: line 1 column 7 (char 6)- JSON Editor Free says
- Expected a value but found "N"
- Cause
- The text came from printing a Python object: Python writes None, True and False, while JSON uses null, true and false.
- Fix
- Write the data with json.dumps(data). Python's own json module rejects this text too.
- Repair
- returns
{"a": null}
NaN or Infinity
- Text
{"a": NaN}- JavaScript says
SyntaxError: Unexpected token 'N', "{"a": NaN}" is not valid JSON- Python says
- nothing: json.loads accepts it
- JSON Editor Free says
- Expected a value but found "N"
- Cause
- JSON has no NaN or Infinity. Python's json module reads and writes them by default, so a file made by Python can parse in Python and fail in JavaScript.
- Fix
- In Python, use json.dumps(data, allow_nan=False): it raises "Out of range float values are not JSON compliant" so you can replace those values with null first.
- Repair
- returns
{"a": "NaN"}
Cut-off document
- Text
{"a": [1, 2- JavaScript says
SyntaxError: Expected ',' or ']' after array element in JSON at position 11 (line 1 column 12)- Python says
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 12 (char 11)- JSON Editor Free says
- Unexpected end of the document: expected a comma or a closing bracket ]
- Cause
- The text stops before the document ends: an interrupted download, a log line cut at a size limit, a file still being written, or a stream read before it finished.
- Fix
- Get the whole document again. Repair closes the open brackets so you can read what is there, but whatever was cut off is lost.
- Repair
- returns
{"a": [1, 2]}
Unterminated string
- Text
{"a": "x}- JavaScript says
SyntaxError: Unterminated string in JSON at position 9 (line 1 column 10)- Python says
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 7 (char 6)- JSON Editor Free says
- This string is never closed: a closing " is missing
- Cause
- A string has no closing quote, or a quote inside the text was not escaped. JavaScript reports where the text ran out; Python reports where the string started.
- Fix
- Close the string, and write a quote inside a string as \".
- Repair
- returns
{"a": "x"}
Line break or tab inside a string
- Text
- {"a": "line⏎break"} (a real line break inside the string)
- JavaScript says
SyntaxError: Bad control character in string literal in JSON at position 11 (line 1 column 12)- Python says
json.decoder.JSONDecodeError: Invalid control character at: line 1 column 12 (char 11)- JSON Editor Free says
- Bad control character in a string: escape it, for example \n
- Cause
- A raw line break or tab inside a string, often from building JSON by joining strings by hand.
- Fix
- Escape it as \n or \t. JSON.stringify and json.dumps do this for you.
- Repair
- returns
{"a": "line\nbreak"}
Number with a leading zero
- Text
{"a": 01}- JavaScript says
SyntaxError: Unexpected number in JSON at position 7 (line 1 column 8)- Python says
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 8 (char 7)- JSON Editor Free says
- Invalid number: a leading zero must not be followed by digits
- Cause
- JSON numbers cannot start with 0 unless they are 0 or 0.something. Postcodes, phone numbers and IDs with leading zeros are text, not numbers.
- Fix
- Write them as strings ("01"), or as the number without the zero (1) if it really is a number.
- Repair
- returns
{"a": "01"}
Text after the end (two documents, a comment)
- Text
{"a": 1} // note- JavaScript says
SyntaxError: Unexpected non-whitespace character after JSON at position 9 (line 1 column 10)- Python says
json.decoder.JSONDecodeError: Extra data: line 1 column 10 (char 9)- JSON Editor Free says
- Unexpected text after the end of the document
- Cause
- There is more after the first complete value: a comment (JSON has no comments), a stray character, or several documents one after another, as in JSON Lines (NDJSON) files and logs.
- Fix
- Delete the comment or the extra text. For JSON Lines, parse each line on its own.
- Repair
- returns
{"a": 1}
Invisible byte order mark (BOM) at the start
- Text
- {"a": 1} starting with an invisible U+FEFF
- JavaScript says
SyntaxError: Unexpected token '', "{"a": 1}" is not valid JSON- Python says
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)- JSON Editor Free says
- nothing: it opens the text as it is
- Cause
- Some Windows editors and export tools save UTF-8 with a byte order mark. It does not print, so the JavaScript message looks like an empty token. Node.js keeps it when you read a file with fs.readFileSync(path, "utf8").
- Fix
- In Python, open the file with encoding='utf-8-sig'. In JavaScript, remove it first: text.replace(/^\uFEFF/, ''). Saving the file as UTF-8 without BOM fixes it for good.
- Repair
- not the fix here: the text is not broken JSON, so fix where it came from
Read the position in the message
JavaScript's "position 16" counts characters from the start of the text, beginning at 0. Newer engines add "(line 1 column 17)", where lines and columns start at 1. Python gives "line 1 column 16 (char 15)": the same 0-based count as "char", with 1-based line and column.
The position is where the parser gave up, which can be after the real mistake. For a trailing comma, JavaScript points at the } after the comma, Python at the comma. Look just before the position as well as at it.
In JSON Editor Free, paste the text in text mode: the status bar shows the line, the column and what is wrong, the spot is underlined, and the Go to next error shortcut jumps to it.
Debug a JSON error from an API
Most JSON errors in code are not broken JSON but a response that is not JSON at all. Read the body as text first, so the error shows you what arrived:
const res = await fetch(url);
const text = await res.text();
if (!res.ok) throw new Error(`HTTP ${res.status}: ${text.slice(0, 200)}`);
let data;
try {
data = JSON.parse(text);
} catch (err) {
console.error(err.message, res.headers.get('content-type'), text.slice(0, 200));
throw err;
}In Python, the exception carries the message, the line, the column and the position, so you can print the text around it:
import json
try:
data = json.loads(text)
except json.JSONDecodeError as err:
print(err.msg, 'line', err.lineno, 'column', err.colno)
print(repr(text[max(0, err.pos - 40):err.pos + 40]))
raiseFix the JSON in the editor
When the text itself is broken, open the free online JSON editor, paste the text or open the file, and press Repair. It fixes quotes, commas, brackets and Python values, then checks the result with the same parser. Nothing is uploaded: the text is read and repaired in your browser. The JSON formatter and repair guide shows more examples, and JSON Schema validation catches JSON that parses but has the wrong shape.
Use this checklist
JSON Editor Free, “JSON parse errors: what each message means and how to fix it”, https://jsoneditorfree.com/json-parse-errors/, tested 30 November 2026.
You may copy and adapt this checklist under CC BY 4.0, with a link to this page. Each error has its own anchor (for example https://jsoneditorfree.com/json-parse-errors/#unexpected-end) so you can link to one message.
Frequently asked questions
What does "Unexpected end of JSON input" mean?
JSON.parse reached the end of the text before the document was complete. Usually the text is empty, for example a response with no body, so check the status and read the body as text before you parse it.
What does "Unexpected token < in JSON at position 0" mean?
The text starts with <, so it is an HTML page, not JSON: an error page, a login page or a wrong URL. Newer Chrome and Node.js versions say "Unexpected token '<', "<!DOCTYPE "... is not valid JSON". Check the URL, the status code and the Content-Type header.
What does "position" mean in a JSON error?
It counts characters from the start of the text, beginning at 0. Newer JavaScript engines add the line and column, which start at 1. Python gives the line, the column and the same 0-based count as "char".
What does "Expecting value: line 1 column 1 (char 0)" mean in Python?
json.loads found no JSON value at the very start: the text is empty, or it starts with something that is not JSON, such as an HTML page or the word undefined.
Why does Python accept NaN in JSON but JavaScript does not?
NaN and Infinity are not part of JSON. Python's json module allows them by default; use json.dumps(data, allow_nan=False) to make Python refuse them too.
Can I fix invalid JSON automatically?
For syntax errors such as single quotes, missing or trailing commas, unquoted keys and cut-off brackets, yes: paste the text into JSON Editor Free and press Repair. When the text is not JSON at all, such as an HTML page or the word undefined, fix where it came from instead.