JSON error reference
Every common way JSON.parse fails, what the message is really pointing at, and the fix. Each page has a broken example and a working one you can open in the validator.
Two things make these errors harder to read than they need to be. First, the position in the message is where the parser gave up, not where you went wrong. A missing comma usually gets reported a token or two late. Second, every engine words the same failure differently, and V8 changed its own wording around Chrome 109. What used to read Unexpected token } in JSON at position 8 now reads ...is not valid JSON with a snippet. Each page below lists the wordings you are likely to see, so you can match yours.
- Unexpected token in JSON at position N
JSON.parsehit a character it cannot accept. The position it gives you is where it stopped, not where you went wrong. The real mistake is usually a few characters earlier, so look just before that spot for a stray comma, the wrong kind of quote, or a missing brace. - Unexpected end of JSON inputYour JSON stopped early. The parser was still waiting for a closing brace, a closing quote, or in some cases for any content at all. This error gives you no position to look at, because the problem is what is missing rather than what is there. Nine times out of ten the string was simply empty.
- Trailing comma in JSONA comma separates two values. Put one directly before
}or]and JSON rejects it. The same line is perfectly legal in a JavaScript object or array, and has been since ES5, which is exactly why this one catches people out. - Single quotes in JSONJSON defines exactly one string delimiter: the double quote. Single quotes are not an alternative form, they are not valid anywhere, and that applies to property names as well as to values.
- Unquoted property names in JSONIn JSON a key is a string, so it needs double quotes, then a colon. There is no bare-identifier form, so
{name: "Ada"}is invalid however ordinary the key looks. - NaN and Infinity in JSONThe JSON number grammar covers an optional minus sign, digits, an optional fraction and an optional exponent.
NaN,Infinityand-Infinitymatch none of that, and JSON has no literal for them. - Byte order mark (BOM) breaks JSON.parseA byte order mark is the character U+FEFF, written as the bytes
EF BB BFin UTF-8. It renders as nothing at all, and RFC 8259 does not permit it at the start of a JSON document: so a file that looks flawless fails at position 0. - Comments are not allowed in JSONJSON deliberately has no comments. They were removed from the format early on, on the grounds that people would use them to carry parsing directives: so
//and/* */are both syntax errors. - "undefined" is not valid JSONSomething converted the value
undefinedto the six-character string"undefined"and handed that toJSON.parse. JSON has noundefinedliteral: the absent value in JSON isnull. - Bad escaped character in JSON stringsInside a JSON string a backslash may be followed by only these:
",\,/,b,f,n,r,t, orufollowed by exactly four hex digits. Anything else is a bad escape. Separately, the raw control characters U+0000 to U+001F may never appear literally in a string: they have to be escaped. - Unexpected token '<', "<!DOCTYPE "... is not valid JSONYour code asked for JSON and got an HTML page instead.
<!DOCTYPE html>is how an HTML page starts, and no JSON document can start with<. Nothing is wrong with your parsing code. The problem is the response, so the fix is to find out why the server sent a page. - Unexpected non-whitespace character after JSON at position N
JSON.parsereads exactly one value. It read one, the value was fine, and then it found more text. Your first value is not broken. Something follows it, and the position tells you exactly where that something starts. - Expecting value: line 1 column 1 (char 0)Python got to a spot where a value has to begin and found something that cannot begin one. Read the offset first.
char 0means the document was empty, or was never JSON at all. Any larger number means one bad value inside a document that is otherwise fine. - Expecting property name enclosed in double quotesThe parser was at a spot where a key has to begin, just after a
{or just after a comma, and the next character was not a double quote. In JSON every key is a string, and every string is double-quoted. There is no second option. - Extra data: line 1 column N (char N)
json.loadsreads exactly one JSON value and then stops. This message means it read one just fine and found more text sitting after it. Your file is not broken. It is two documents where the parser expected one, and the offset tells you where the second one starts. - Expecting ',' delimiterThe parser finished one value and found the next one starting straight away, with no comma between them. Here is the trap. You get this same message when a comma is genuinely missing and when a string ended earlier than you meant it to. The second case is far more common, so check your quotes first.
- Unrecognized token: was expecting a valueJackson lists the seven things a JSON value can be, because it found something that was none of them: a bare run of letters. The token it quotes back at you is the exact text it could not classify, which usually makes the cause obvious.
- Unexpected character ('}' (code 125))Jackson gives you the character it found, its decimal code, and then what it wanted instead. Read the second half first. "was expecting double-quote to start field name" means it was waiting for the next key, which is exactly what a trailing comma promises and never delivers.
- json_decode() returns null
json_decodedoes not throw by default. It returnsnulland expects you to ask what happened.nullis also the correct result for the inputnull, so the return value on its own genuinely cannot tell you whether anything went wrong:json_last_error()is the only way to know. - invalid character '<' looking for beginning of valueGo tells you two things: the byte it could not use, and what it was in the middle of reading. "looking for beginning of value" means it was at the start of a value, so the byte quoted is the very first character of something that was supposed to be JSON (which is why
<is the one people see most).
Not sure what JSON is yet?
Start with what is a JSON file. It covers the format, its six types, and the three mistakes behind most of the errors above. If you just need to open one, how to open a JSON file covers every platform.
The fastest way to find any of them
Paste the document into the JSON validator. It turns the parser's character offset into a line and column, highlights the spot, and repairs the mistakes that can be repaired safely. Nothing is uploaded. The parsing happens in your browser.