"Unexpected token" is the error message a JSON parser gives when it meets a character it was not expecting. The text you gave it is not valid JSON, and it stopped at the first place where that became clear. The fastest way to find that place is to paste the text into the free JSON Validator, which shows the exact line and column, marks the spot with a caret and explains the problem in plain English.
This guide explains what the message means, the handful of causes behind almost every case, and how to fix each one.
What the message actually says
Different tools word it differently. You might see:
Unexpected token } in JSON at position 25(older Chrome and Node.js)Unexpected token '}', "{"a":1,}" is not valid JSON(newer Chrome and Node.js)JSON.parse: unexpected character at line 1 column 1 of the JSON data(Firefox)JSON Parse error: Unexpected token '}'(Safari)
They all mean the same thing: the text broke JSON's rules at the stated position. The wording and the position format differ, so do not worry about matching the message exactly. What matters is the character it names and where it sits.
One thing to remember is that a parser reports where it first noticed the problem, which is not always where the mistake is. A missing comma is only noticed when the next item starts.
Step 1: find the exact spot
Paste your text into the JSON Validator, either typing into "Paste or type JSON" or pressing Open file. It checks as you type and shows a red note: "Invalid JSON — line 3, column 12", then a reason, the line itself and a ^ under the position. Columns count from 1.
The validator reports one error at a time, the first it finds. Fix it, and the next one, if there is any, shows up straight away.
Step 2: match your case
Case 1: "Unexpected token <" at the very start
This is the classic. The message points at line 1, column 1 or "position 0", and the validator says:
Unexpected "<" — expected a value (object, array, string, number, true, false or null).
The text begins with <, so it is HTML, almost always an error page. The server did not send JSON. Typical reasons:
- The request address is wrong, so the server returned a "404 Not Found" page.
- You are not logged in, and the server sent a login page.
- The server crashed and returned an error page.
- A proxy, firewall or captive Wi-Fi page intercepted the request.
Fix the request, not the JSON. Look at the response in the browser's Network tab, check the status code and the address, and look at the first characters of the body.
Case 2: a trailing comma
Trailing comma — JSON doesn't allow a comma before "}".
{"name": "Rahim", "age": 25,}
The same message is given for "]". Delete the comma after the last item. JavaScript lets you leave one there, but JSON does not.
Case 3: a missing comma
Expected "," or "}" but found a double quote ("). You may be missing a comma between two values.
{"name": "Rahim" "age": 25}
The caret sits at the start of "age". The comma is missing at the end of the previous item, so look just before the reported spot.
Case 4: single quotes
Strings must use double quotes, not single quotes.
{'name': 'Rahim'}
For a key you get "Property names must use double quotes, not single quotes." Replace every single quote that delimits a string with a double quote. This happens a lot when JSON is typed by hand or copied from Python output.
Case 5: keys without quotes
Property names must be wrapped in double quotes, e.g. "name": …
{name: "Rahim"}
This is valid in JavaScript but not in JSON. Put the key in double quotes.
Case 6: comments
Comments aren't allowed in JSON. Remove them (Auto-fix can do this).
{
// applicant details
"name": "Rahim"
}
Standard JSON has no comment syntax. Delete the comments, or if you want to keep a note, put it in a normal field.
Case 7: Python or JavaScript values
Unexpected word "None". Use "null" instead of None.
True, False and None come from Python, and undefined and NaN from JavaScript. JSON uses lowercase true, false and null. The validator's message names the replacement. A common cause is printing a Python dictionary and pasting it as JSON.
Case 8: a number with a leading zero
Numbers can't have leading zeros.
{"phone": 01712345678}
A Bangladeshi mobile number, an NID or a roll number is an identifier, not a quantity, so write it as a string: "phone": "01712345678".
Case 9: a bracket missing or in the wrong place
Unexpected end of input — missing a closing "}" (1 bracket still open).
The text stopped before everything was closed. Add the missing closer at the end, or find the object you forgot to close. Another form is "Mismatched brackets: found "}" but the open "[" needs "]" first", which means a closer of the wrong type.
Case 10: more than one value
Unexpected "{" after the end of the JSON value. A JSON document can contain only one top-level value.
Two objects pasted one after another is not one JSON document. Put them in an array, separated by a comma: [{...},{...}]. Newline-delimited log files, with one object per line, hit this too.
Case 11: a bad escape or a line break in a string
Invalid escape sequence "\d" inside a string.
Inside a string only \" \\ \/ \b \f \n \r \t and \uXXXX are allowed after a backslash. A Windows path needs doubled backslashes: "C:\\Users\\Rahim".
A raw Enter press inside a string gives "Unescaped line break inside a string". Write the break as \n instead.
Case 12: an empty response
An empty string is not JSON. If the validator shows only the blue "Paste JSON…" hint, there is nothing to parse. In your code, check that the request returned a body before you call JSON.parse.
Step 3: let Try auto-fix do the boring ones
For cases 2, 4, 5, 6 and 7 you do not have to edit by hand. Under the red message there is a Try auto-fix button, with the hint "Fixes comments, single quotes, unquoted keys, trailing commas and True/False/None." Click it and the repaired text replaces what is in the box, with a list of the changes, such as "Removed 1 trailing comma".
It will not add a missing comma, close a bracket or repair a broken string. If it cannot safely change anything, it says so and you fix the spot by hand, using the line and column. Press Broken sample first if you would like to watch it work.
Step 4: check the result
When the note turns green with "Valid JSON ✓", the syntax is right. To read it comfortably, use the JSON Formatter, or switch to Tree view on the same page. If a program still rejects the data, the problem is no longer syntax: look at field names, types and required fields. Remember that valid JSON only proves the syntax is correct.
For the full list of messages and what they mean, see the JSON Validator guide. If you only want to read a response, how to read a minified JSON API response takes less time.
Preventing the error
- Never build JSON by joining strings by hand. Use
JSON.stringifyin JavaScript orjson.dumpsin Python, and let the library add the quotes and commas. - Check the status code before parsing a response.
- Keep phone numbers, NIDs and long IDs as strings.
- Keep comments in a separate file or a field, not in the JSON.
- Validate any hand-edited config file before you use it.
Our validator runs in your browser, so you can safely check private API responses and configuration files.



