Guides › Text & developer
"Expected property name" and other JSON errors: what 14 broken inputs tell you
JSON error messages are short and literal. They tell you where the parser gave up, not what you did wrong, and the place where it gave up is often one character after the real mistake. To make the messages easier to decode we wrote 14 small inputs that each contain one typical mistake, ran them through JSON.parse() with the V8 engine in Chromium 153 (as used by Chrome and Edge; Node.js also uses V8, but its version and so its wording may differ) and recorded exactly what came back.
Short answer: the position in a JSON error is where the parser gave up, which is often one character after the real mistake. Most messages come from a handful of causes: a trailing comma, single or curly quotes, an unquoted key, a missing comma or a comment. One mistake gives no error at all: integers longer than about 16 digits are silently rounded. Paste your text into our JSON formatter to see the exact spot.
The results
| Mistake | Input | Chrome's message |
|---|---|---|
| Trailing comma | {"a":1,} | Expected double-quoted property name in JSON at position 7 |
| Single quotes | {'a':1} | Expected property name or '}' in JSON at position 1 |
| Unquoted key | {a:1} | Expected property name or '}' in JSON at position 1 |
| Curly "smart" quotes | {“a”:1} | Expected property name or '}' in JSON at position 1 |
| Comment | {"a":1 // note} | Expected ',' or '}' after property value in JSON at position 7 |
| Missing comma | {"a":1 "b":2} | Expected ',' or '}' after property value in JSON at position 7 |
| Hex number | {"a":0x10} | Expected ',' or '}' after property value in JSON at position 6 |
| Leading zero | {"a":012} | Unexpected number in JSON at position 6 |
| NaN | {"a":NaN} | Unexpected token 'N', ... is not valid JSON |
| undefined | {"a":undefined} | Unexpected token 'u', ... is not valid JSON |
| Raw line break inside a string | {"a":"line1⏎line2"} | Bad control character in string literal in JSON at position 11 |
| Byte order mark at the start | BOM + {"a":1} | Unexpected token '', ... is not valid JSON (the token looks empty) |
| Empty input | (nothing) | Unexpected end of JSON input |
| Very large integer | {"id":12345678901234567891} | No error, but the value became 12345678901234567000 |
Chrome also adds "(line 1 column 8)" style coordinates after the position. Positions count characters from zero, so position 7 is the eighth character.
Reading the four message families
"Expected property name or '}'" or "Expected double-quoted property name"
The parser was inside an object and wanted a key in double quotes. Look at the character at the reported position. If it is ', “ or a bare word, the key is not double-quoted. If the position points at }, the character before it is a trailing comma: the parser saw the comma, expected another key and found the closing brace instead. Curly quotes usually come from pasting JSON through a word processor or a chat app that "beautifies" punctuation.
"Expected ',' or '}' after property value"
A value ended and something other than a comma or closing bracket followed. Three causes cover almost every case: a missing comma between two entries, a comment (JSON has none), or a value JSON does not understand, such as the hex number 0x10, where the parser reads 0 as a complete number and then trips over x. That is why the position points one character after the real problem.
"Unexpected token 'X'"
The parser met a character that cannot start any JSON value. N means NaN, u means undefined, I means Infinity: all JavaScript values that have no JSON form. A common source is code that builds JSON by string concatenation instead of JSON.stringify(), which turns NaN and Infinity into null and leaves out properties whose value is undefined. If the token shown is <, you almost certainly received an HTML page, often a login screen or a server error page, instead of the JSON you asked for.
"Unexpected end of JSON input"
The text stopped before the structure was complete. Either the response was empty (check the HTTP status and whether the server sent anything), or a closing } or ] is missing, or the data was cut off in transfer.
The two traps that give no useful error
The invisible byte order mark. Some Windows editors save UTF-8 files with three invisible bytes at the start. Chrome reports an "unexpected token" that appears blank, which is baffling until you know the cause. Re-save the file as "UTF-8" rather than "UTF-8 with BOM", or strip the first character before parsing.
Silent number rounding. The last row of our table is the most dangerous because it does not fail. JavaScript numbers are 64-bit floating point and can represent integers exactly only up to 9,007,199,254,740,991. Our 20-digit ID was quietly rounded and its last digits changed. Our formatter has the same limit: it re-serialises the parsed value, so such an ID comes out rounded. It shows a warning, but do not copy formatted output of that kind of data back into production. Large IDs from databases, social networks and payment systems should be sent as strings, for example {"id":"12345678901234567891"}.
A quick routine for any JSON error
- Paste the text into our JSON formatter and press Beautify. For invalid JSON the tool shows the error, usually with a line and column; it cannot indent text that does not parse, so go to that line and column. When no position is given, look at the token the message names and at the very first character of the input.
- Look one or two characters before the reported position, not just at it.
- Check the first character. If it is
<you have HTML; if the message mentions a blank token, suspect a BOM. - If a corrected file still behaves strangely, compare it with a known good version in the text compare tool to see every changed line.
Why JSON is so strict
The JSON standard (RFC 8259 and ECMA-404) deliberately has no comments, no trailing commas, no single quotes and no special number values. The strictness is the point: every parser in every language must agree on what a document means. Formats such as JSON5 and JSONC relax these rules for hand-edited configuration files, but a strict parser such as JSON.parse() or a web API will reject them. If you want comments in a config file, make sure the program that reads it actually supports that variant.
What our formatter showed, and where rounding starts
We pasted each of the 14 inputs into our JSON formatter in Chromium 153 and pressed Beautify. Then we fed it 36 whole numbers between 15 and 20 digits long to find exactly where rounding begins.
- For all 13 invalid inputs the formatter showed "Invalid JSON:" followed by the browser's own message word for word. In the 9 cases where the browser gives a line and column, the formatter showed them too; the empty input, BOM, NaN and undefined cases have no position. The table above therefore applies to the formatter as well.
- The 20-digit ID was accepted as valid, with a note that numbers beyond 15–16 digits are rounded by the browser, and came out as 12345678901234567000.
- All five 15-digit and five 16-digit samples (each below 9,007,199,254,740,991) came back unchanged, but 16 digits alone is not a safe rule: see the limit below. At 17 digits only 1 of 5 survived; from 18 to 20 digits none of 15 did.
- Right at the limit, 9007199254740990, …991, …992 and …994 stayed exact, but …993 became …992 and …995 became …996. Above 253 only every second integer can be stored, so odd numbers move to a neighbour.
You can download the inputs and outputs. Each file is plain CSV with a header row:
- The 14 inputs: columns mistake, input_escaped (the input with quotes and control characters escaped), json_parse_message and formatter_message.
- 36 large integers: columns input, digits, formatter_output and unchanged (yes or no).
Common questions
Do Firefox and Safari show the same messages?
No. Each JavaScript engine words its errors differently, and Chrome's own wording has changed between versions. The causes are the same, so the families above still apply; only the text differs.
Is it safe to paste private JSON into an online formatter?
Ours formats the text inside your browser and does not upload it. In general, avoid pasting live passwords, API keys or customer data into any tool you have not checked.
Why does my valid-looking JSON fail only when loaded from a file?
Usually a BOM or the wrong text encoding. Open the file in an editor that shows encoding and re-save it as UTF-8 without BOM.
References
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- ECMA-404: The JSON Data Interchange Syntax
- MDN: JSON.parse()
- MDN: Number.MAX_SAFE_INTEGER
Written and checked by Ria Kim for GlowHalo; figures without a source link come from the steps shown on this page. Companion tool: JSON Formatter & Base64. Spotted an error? Write to help@glowhalo.org. Windows, Chrome, Chromium, Safari, Firefox and Edge are trademarks of their owners; GlowHalo is not affiliated with them.