JSON Text Tools

Jsonformatter and Text Tools
Home › Guides › How to Fix "Unexpected token" Errors in JSON

How to Fix "Unexpected token" Errors in JSON

Updated November 2026

"Unexpected token" means the parser met a character that JSON does not allow at that position. The message is vague, but the cause is almost always one of five mistakes.

1. Trailing comma

JavaScript tolerates a comma after the last item; JSON does not.

{"a": 1, "b": 2,}   // invalid
{"a": 1, "b": 2}    // valid

2. Single quotes

Strings and keys must use double quotes.

{'name': 'Mary'}    // invalid
{"name": "Mary"}    // valid

3. Unquoted keys

Every key is a double-quoted string. {name: "Mary"} is a JavaScript object, not JSON.

4. Comments

JSON has no comment syntax. Remove // and /* */ before parsing, or use a format such as JSONC for config files.

5. The input is not JSON at all

If the error says Unexpected token < at position 0, your code probably received an HTML error page instead of JSON. Check the HTTP status and response body. An empty response gives "Unexpected end of JSON input".

Find it faster

Paste the text into the JSON Formatter. It parses with the strict standard rules and reports the error, so you can fix one problem at a time.

Message here