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.
Different environments phrase the error differently, but they all mean the same thing:
SyntaxError: Unexpected token X in JSON at position Njson.decoder.JSONDecodeError: Expecting value: line N column NMismatchedInputException: Unexpected character 'X'invalid character 'X' looking for beginning of valueAll 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.
} — trailing comma before closing braceThe 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.
] — trailing comma in arrayInvalid:
["admin", "editor", "viewer",]
Valid:
["admin", "editor", "viewer"]
' — single quotesJSON 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.
n, a, or other letters — unquoted keyWhen 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}
< — response is HTML, not JSONThis 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.
/ — comment in JSONJSON does not support comments. A // or /* character causes an immediate parse failure.
Invalid:
{
// user record
"name": "Ava"
}
Valid:
{
"name": "Ava"
}
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.
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"}]
<: stop editing the JSON and inspect the raw API response instead — the issue is the request, not the parser.} or ] after a comma — trailing comma before the closing bracket' — single quotes used instead of double quotesn, a, t at key position — unquoted object key< at position 0 — server returned HTML, not JSON/ — comment present in the JSON} or ] — extra content or concatenated payloadsPaste 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.
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.
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.
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.
Seeing an unexpected token error? Validate the JSON and jump to the broken line.
Validate JSON