Unexpected token in JSON at position N
SyntaxError: Unexpected token ']', ..." "editor",], }" is not valid JSON
Where it stops
"name": "Ada",
"roles": ["admin", "editor",],
}What it means
JSON.parse hit 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.
Last verified on Chromium 145, Firefox 146 and WebKit 26.
It opens with the error marked. Nothing is uploaded. Find where the error is.
- Usually
- You parsed something that was never JSONA stray or missing commaThe wrong kind of quoteDouble-encoded JSON
- Fix
- Delete the comma after the last array item, and the comma after the last object key.
The fix
Delete the comma after the last array item, and the comma after the last object key. A comma goes between two values, never after the last one.
{
"name": "Ada",
"roles": ["admin", "editor",],
}Line 3: delete , twice.
{
"name": "Ada",
"roles": ["admin", "editor"]
}How the message appears
Chrome and Node first, then Firefox, then Safari. Older versions of Chrome and Node word it differently. Those lines are marked.
- SyntaxError: Unexpected token ']', ..." "editor",], }" is not valid JSONChrome and Node
- SyntaxError: JSON.parse: unexpected character at line 3 column 31 of the JSON dataFirefox
- SyntaxError: JSON Parse error: Unexpected comma at the end of array expressionSafari
- SyntaxError: Expected double-quoted property name in JSON at position 8 (line 1 column 9)
- SyntaxError: "[object Object]" is not valid JSON
- SyntaxError: Unexpected token } in JSON at position 8Older V8 wording
What causes it
You parsed something that was never JSON
Current Chrome and Node say
"[object Object]" is not valid JSON, and you can read the answer straight out of it. Older V8 saidUnexpected token o in JSON at position 1. Position 0 is[and position 1 iso, so either way the text being parsed is[object Object]. Something turned an object into a string withString(value)beforeJSON.parseever saw it. The other common one isUnexpected token <. That means you parsed an HTML page, and it is almost always a 404 or 500 page arriving where you expected JSON.A stray or missing comma
Either a comma after the last item, or no comma between two items. JavaScript lets you leave a comma after the last one. JSON does not. That is why code copied out of an editor so often breaks right here.
The wrong kind of quote
Single quotes, backticks, or the curly quotes that Word, Slack and Notion insert for you (‘ ’ “ ”). They look almost identical on screen. JSON strings take plain double quotes and nothing else.
Double-encoded JSON
The document holds a JSON string where you wanted a JSON object, so you have
"{\"a\":1}"instead of{"a":1}. Parsing that once hands you back a string, not an object. Something ranJSON.stringifytwice on the way in.
Worth knowing
NoteThe position counts characters from the start of the string, not lines. Paste the document into the validator and it turns that number into a line and column you can find.
NoteIf the position is 0 and the document looks perfect, you probably have a byte order mark. See the BOM page.