JSON Parse Error: Unexpected Token

What it means, why it happens, and how to fix it.

A "JSON Parse Error: Unexpected Token" message means the JSON parser reached a character it did not expect at that position. The parser knows the grammar of valid JSON precisely — it knows which characters are legal at every point in the document — so when it finds something out of place, it stops immediately and reports the location. This guide explains every common cause of this error, shows what the broken and fixed JSON looks like, and covers how to debug cases where the token is not what it appears.

How JSON Parsers Report This Error

Different environments phrase the error differently, but they all mean the same thing:

All of these tell you where the parser stopped. The real mistake is usually at or just before that position — either a missing comma before the reported token, an extra comma before a closing bracket, or a character that has no business being in JSON at all.

Every Common Cause — With Examples

Unexpected token } — trailing comma before closing brace

The parser found a closing brace after a comma, which means it expected another key-value pair and got a closing brace instead.

Invalid:

{
  "name": "Ava",
  "active": true,
}

Valid:

{
  "name": "Ava",
  "active": true
}

This is the most common JSON error across all environments. JSON does not allow trailing commas anywhere — neither after the last property in an object nor after the last element in an array.

Unexpected token ] — trailing comma in array

Invalid:

["admin", "editor", "viewer",]

Valid:

["admin", "editor", "viewer"]

Unexpected token ' — single quotes

JSON requires double quotes for all strings and keys. Single quotes are JavaScript syntax, not JSON syntax.

Invalid:

{'name': 'Ava', 'active': true}

Valid:

{"name": "Ava", "active": true}

Use Auto-fix in the JSON Formatter to replace all single quotes at once across a large payload.

Unexpected token n, a, or other letters — unquoted key

When the parser encounters a letter where it expects a quoted string key, it reads it as an unrecognised token. This happens when JSON is copied from JavaScript source code where keys are not quoted.

Invalid:

{name: "Ava", active: true}

Valid:

{"name": "Ava", "active": true}

Unexpected token < — response is HTML, not JSON

This is one of the most confusing errors for developers debugging API calls. The response body starts with < because the server returned an HTML page — typically a 404 error page, a login redirect, a maintenance page, or a CORS error — instead of JSON.

What you see:

SyntaxError: Unexpected token < in JSON at position 0

What the response actually contains:

<!DOCTYPE html>
<html>
  <body><h1>404 Not Found</h1></body>
</html>

To debug this, log or inspect the raw response body before parsing. In browser DevTools, open the Network tab, find the request, and look at the Response tab. If it shows HTML, the issue is in the request — wrong URL, missing authentication, expired session, or a server-side error.

Unexpected token / — comment in JSON

JSON does not support comments. A // or /* character causes an immediate parse failure.

Invalid:

{
  // user record
  "name": "Ava"
}

Valid:

{
  "name": "Ava"
}

Unexpected token at position 0 — BOM or invisible character

If the error occurs at position 0 but the JSON looks correct, a byte-order mark (BOM) or invisible Unicode character is likely at the start of the file. This happens when JSON files are saved with a BOM by certain editors on Windows, or when text is copied from a PDF, Word document, or documentation site that inserts non-printable characters.

Paste the JSON into the formatter — it strips the BOM and flags invisible characters in the editor. You can also open the raw bytes in a hex editor to confirm: a UTF-8 BOM appears as EF BB BF at the start of the file.

Unexpected token after valid JSON ends — extra content

Some parsers expect only one value at the top level. If your text contains two JSON objects concatenated without an enclosing array, the parser succeeds on the first object and then sees unexpected content.

Invalid (two concatenated objects):

{"name": "Ava"}{"name": "Ben"}

Valid (array of objects):

[{"name": "Ava"}, {"name": "Ben"}]

Step-by-Step Debugging Workflow

  1. Paste the text into the JSON Formatter. The editor highlights the first error position with a red marker and shows the line and column number.
  2. Read the token in the error message. Use the table below to identify the likely cause before looking at the code.
  3. Look at the character before the reported position. The reported token is usually valid on its own — the mistake is what precedes it (a missing comma, an extra comma, an unclosed string).
  4. Click Auto-fix for common issues: trailing commas, single quotes, unquoted keys, comments. Revalidate after.
  5. If the token is <: stop editing the JSON and inspect the raw API response instead — the issue is the request, not the parser.

Quick Reference: Token to Cause

Frequently Asked Questions

The error says position 482. How do I find that in a large file?

Paste the JSON into the formatter — the editor highlights the error at the exact line and column so you do not need to count characters manually. For very large payloads, the tree view also marks the first node with a structural problem.

My JSON passes in one parser but fails in another. Why?

Some parsers are lenient and accept extensions like trailing commas, single quotes, or comments. If your JSON relies on these, it is technically invalid and will fail in strict parsers. Always target strict JSON compliance — write JSON that passes validation in the formatter, not just in a permissive library.

Why does the error position sometimes seem wrong?

Parsers count character positions from zero, and they often count all characters including whitespace. The reported position points to where the parser gave up, not necessarily where you made the mistake. The real error is usually a few characters earlier — look at the token just before the reported position.

Can an unexpected token error happen inside a string?

Yes — if a string contains an unescaped double quote, the parser thinks the string ended early and then finds unexpected content. For example, {"message": "He said "hello""} is invalid because the inner double quotes close and reopen the string in an unexpected way. Escape them: {"message": "He said \"hello\""}.

Try what you just learned — paste your JSON into the formatter and validate it instantly. Free, browser-only, no data sent anywhere.

Related Guides

Seeing an unexpected token error? Validate the JSON and jump to the broken line.

Validate JSON