JSON looks like JavaScript, but its rules are much stricter. Many things that work in JavaScript, Python or YAML are not allowed in JSON.
These small habits cause most “Unexpected token” errors. Here are the eight errors we see most often, and how to fix each one.
Quick answer: Most JSON errors come from an extra comma at the end, single quotes, keys without quotes, or comments. Use double quotes for all keys and strings. Remove comments and the last comma in each list or object.
1. Extra comma at the end (trailing comma)
{ "name": "Ada", "languages": ["en", "fr",], }JavaScript and most modern languages let you put a comma after the last item. JSON does not.
Remove the comma before every closing ] and }. This is the most common JSON error of all. It often happens when you delete the last item from a list.
2. Single quotes
{ 'name': 'Ada' }Strings and key names must use double quotes: { "name": "Ada" }.
Single quotes often come from Python. This happens when you print a Python dictionary with print(data). Use json.dumps(data) instead.
3. Key names without quotes
{ name: "Ada" }This works in a JavaScript object, but not in JSON. Every key must be a string in double quotes.
Are you copying from JavaScript code? Then JSON.stringify(obj, null, 2) gives you real JSON.
4. Comments
{
// timeout in seconds
"timeout": 30
}JSON has no comments. Some files, like tsconfig.json and VS Code settings, use “JSON with Comments” (JSONC). Their own tools accept it, but standard JSON readers do not.
Remove the comments. Or change the file with a JSONC to JSON converter.
5. Missing commas
{
"name": "Ada"
"born": 1815
}You need a comma between each pair in an object, and between each item in a list.
The error message points to the next item, here "born". It does not point to the end of the line before it. So look one line up to find the missing comma.
6. Curly quotes (smart quotes)
{ “name”: “Ada” }Word processors, chat apps and some note apps change straight quotes (") into curly ones (“ ”). They look almost the same, but they are different characters. JSON only accepts the straight kind.
Paste JSON into a code editor or a plain-text box. Never paste it into a rich-text box that adds formatting.
7. undefined, NaN and Infinity
{ "score": NaN, "limit": Infinity, "note": undefined }None of these exist in JSON. Use null for missing values. For special numbers, choose clearly how to store them, for example as null or as a string.
Be careful: JSON.stringify changes NaN and Infinity to null without any warning. It also removes keys whose value is undefined.
8. Special characters inside strings that are not escaped
{ "path": "C:\new\folder", "text": "line one
line two" }A backslash starts an escape, a short code for a special character. So "C:\new" has a new line in it (\n). And \f is a form feed, another hidden character.
Real line breaks and tabs inside a string are not allowed at all. Write "C:\\new\\folder" and "line one\nline two". Or let a JSON escape tool do it for you.
Two problems that pass the check but still cause bugs
- The same key twice. Most JSON readers accept
{"id": 1, "id": 2}. They keep the last value without any warning. Different languages may keep different values. This causes bugs that are hard to find. - A byte-order mark (BOM). Some Windows editors add a hidden character at the start of the file. Many JSON readers then fail on the very first character. The error message can be confusing.
How to read the error message
Browsers show messages like Unexpected token in JSON at position 312. The number counts characters from the start. In a large file, that does not help much.
Free tools can help:
- The JSON Validator shows the exact line and column, with a plain-English explanation.
- The Error Analyzer gives a full report. It also finds the hidden problems above.
- JSON Repair fixes the common errors for you. It lists every change it makes.
Common questions
What does “Unexpected token” mean in JSON?
It means the JSON reader found a character it did not expect. Often this is an extra comma, a single quote or a comment. Check the spot the message points to, and the line before it.
Can JSON have a comma after the last item?
No. JSON does not allow a comma after the last item in a list or object. Remove it.
Can I use single quotes in JSON?
No. All keys and strings must use double quotes. { 'name': 'Ada' } is not valid JSON.
How can I fix broken JSON quickly?
Paste it into JSON Repair. It fixes common errors, like extra commas and single quotes, and shows what it changed.