JSON unexpected token
Invalid JSON syntax: the parser reached a character that cannot legally follow the previous token. The message often includes the offending token and a position (line/column in browsers, byte offset in some servers).
JSON is stricter than JavaScript object literals: no trailing commas, no comments, double quotes only for keys and string values, and no `undefined` or `NaN` literals.
This error usually appears when pasting from Stack Overflow, `.jsonc` config files, or JavaScript where trailing commas and single quotes are allowed.
Common causes
- Trailing comma after the last property or array element (`{"a":1,}` or `[1,2,]`).
- Unquoted or single-quoted keys (`{key: 1}` or `{'a': 1}`) — JSON requires double-quoted keys.
- Single-quoted strings (`'text'`) — JSON strings must use double quotes.
- JavaScript-style comments (`//` or `/* */`) — JSON has no comments.
- BOM (byte order mark) or invisible Unicode at the start of the file confusing the first token.
- Concatenated JSON documents or extra prose before/after the value (common when copying API responses into a file).
- Using `undefined`, unquoted `true`/`false`/`null` in non-value positions, or a stray comma with no following value.
How to narrow it down
- Note the exact character mentioned in the error (often `,`, `'`, `/`, `{`). Search for that pattern near the reported line.
- If the position is “1” or early in the file, check for BOM, HTML pasted into a `.json` file, or multiple `{...}{...}` blobs.
- Validate the smallest failing slice: paste into the JSON validator and bisect (remove half the file) until the error moves.
Examples
{
"name": "demo",
"ok": true,
}Remove the comma after true (last property in the object).
{ name: "demo" }Use double quotes around keys: { "name": "demo" }.
{ 'a': 1 }Use double quotes: { "a": 1 }.
How to fix
- Remove trailing commas after the last element in every object and array.
- Quote every key with double quotes and use double quotes for all string values.
- Strip `//` and `/* */` comments or save as JSONC in an editor that strips them before production use.
- Remove BOM: re-save as UTF-8 without BOM or use your editor’s “Save without BOM”.
- If the payload is built in JavaScript, serialize with JSON.stringify instead of string concatenation.
- Paste into ValidateThis JSON validator to get a precise first error location, then re-run after each fix.
Watch out
- Some APIs return JSON with a `while(1);` prefix or JSONP — strip the wrapper before parsing.
- Large config files may be JSON5 or YAML in disguise; don’t assume the `.json` extension means strict JSON.
Related guides
Use our tool
Validate JSONAdvertisement