JSON parse errors explained: what each message means
By Abhishek Jaiswar ยท Published
A JSON parse error tells you where the parser gave up, which is not always where the mistake is. Find your message below to see the usual cause and the fix.
Find the error in JSONWeaveHow to read a parse error
Every message reports a position, either a character offset or a line and column. The parser stopped there because the text could no longer be valid JSON, so look at that spot and at the token just before it. For a missing closing quote, the real mistake is earlier than the reported position.
The wording depends on the engine. Each section below lists the same problem as Chrome and Node.js (V8), Firefox, Python and .NET (Json.NET) report it.
"Unexpected end of JSON input" and "Expecting value"
The parser reached the end of the text while it still expected a value. The input is either empty, for example a 204 response or a failed request, or it was cut off. If the document starts and ends mid-way, see how to fix truncated JSON.
- Chrome and Node.js: Unexpected end of JSON input
- Firefox: unexpected end of data
- Python: Expecting value: line 1 column 1 (char 0)
"Unexpected token" and "unexpected character"
The text does not start like JSON. A "<" means an HTML page, usually an error page, was parsed as JSON. Other common first characters are a single quote, the word undefined, a byte order mark or a log prefix. Check the response status and headers before the body.
- Chrome and Node.js: Unexpected token '<', "<html>" is not valid JSON
- Firefox: unexpected character at line 1 column 1
- Python: Expecting value: line 1 column 1 (char 0)
"Unterminated string"
A string was opened and the closing quote never came before the end of the text. Either the document was truncated inside a string, or a quote is missing. Everything after the opening quote is read as part of the string, so the reported position is where the text ran out.
- Chrome and Node.js: Unterminated string in JSON at position 7
- Firefox: unterminated string literal
- Python: Unterminated string starting at
- .NET: Unterminated string. Expected delimiter: "
{"id": 7, "message": "Payment recei"Bad control character in string literal"
A raw newline, tab or other control character sits inside a string. JSON requires them to be written as escape sequences such as \n and \t. This often happens when multi-line text is pasted into a string by hand.
- Chrome and Node.js: Bad control character in string literal in JSON at position 7
- Firefox: bad control character in string literal
- Python: Invalid control character at
{"note": "line one
line two"}{"note": "line one\nline two"}"Bad escaped character" and "Invalid \escape"
A backslash is followed by a character that JSON does not define. The valid escapes are \" \\ \/ \b \f \n \r \t and \u followed by four hex digits. Windows paths and regular expressions are the usual culprits, because \d and \x41 are not valid JSON. Double the backslash.
- Chrome and Node.js: Bad escaped character in JSON at position 9
- Firefox: bad escaped character
- Python: Invalid \escape
- .NET: Bad JSON escape sequence
{"path": "C:\data"}{"path": "C:\\data"}"Expected double-quoted property name"
The parser wanted a key and found something else. The usual causes are a trailing comma after the last property, a key in single quotes, or an unquoted key copied from a JavaScript object.
- Chrome and Node.js: Expected double-quoted property name in JSON at position 7, or Expected property name or '}' in JSON at position 1
- Firefox: expected double-quoted property name
- Python: Expecting property name enclosed in double quotes
{"a": 1,}{name: "Ada"}"Expected ',' or '}'" and "Expecting ',' delimiter"
A value ended and the parser found neither a comma nor a closing bracket. Look for a missing comma, a quote inside a string that was not escaped, or a document that ended right after a value, which also reports this message.
- Chrome and Node.js: Expected ',' or '}' after property value in JSON at position 7
- Python: Expecting ',' delimiter
{"a": 1 "b": 2}{"note": "Said "hello" today"}"Extra data" and "Unexpected non-whitespace character after JSON"
The first value parsed fine and more text follows it. This happens with two documents back to back, with JSON Lines or NDJSON logs where each line is its own document, or with stray text after the closing bracket. Parse the file line by line, or wrap the documents in an array.
- Chrome and Node.js: Unexpected non-whitespace character after JSON at position 7
- Firefox: unexpected non-whitespace character after JSON data
- Python: Extra data: line 1 column 9
- .NET: Additional text encountered after finished reading JSON content
{"a": 1}{"b": 2}[{"a": 1}, {"b": 2}]Find the exact spot faster
Counting columns by hand is slow in a large document. JSONWeave marks each problem at its position in the editor with a plain description, and the repair preview shows what the corrected document would look like before you apply it.
Related
Ready to try it on your own JSON?
Open the workspace, paste or drop a file, and nothing leaves your browser.
Find the error in JSONWeave