Unexpected token in JSON at position N

ErrorJavaScript

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.

broken.jsonFails to parse
{
  "name": "Ada",
  "roles": ["admin", "editor",],
}
JSON.parse stops at line 3, column 31.

Line 3: delete , twice.

fixed.jsonParses
{
  "name": "Ada",
  "roles": ["admin", "editor"]
}
JSON.parse reads it.

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.

Console
  • 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

  1. 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 said Unexpected token o in JSON at position 1. Position 0 is [ and position 1 is o, so either way the text being parsed is [object Object]. Something turned an object into a string with String(value) before JSON.parse ever saw it. The other common one is Unexpected token <. That means you parsed an HTML page, and it is almost always a 404 or 500 page arriving where you expected JSON.

  2. 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.

  3. 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.

  4. 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 ran JSON.stringify twice 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.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy