JSON’s syntax is small and strict, and a parser will reject the whole document for a single misplaced character. The error messages are often cryptic: Unexpected token } in JSON at position 214 does not tell you much. This guide lists the mistakes behind nearly all of those messages, with a fix for each.
The fastest way to find the problem is to paste the document into the JSON Formatter & Validator, which reports the exact line and column. The sections below explain what you will find there.
1. Trailing comma
{
"name": "Ada",
"age": 36,
}
JavaScript allows a comma after the last item. JSON does not. The error usually points at the closing brace: Unexpected token }.
Fix: delete the comma after the last property or array item.
2. Single quotes
{ 'name': 'Ada' }
JSON strings and keys must use double quotes. Single quotes are valid JavaScript, which is why this slips in when someone copies an object literal from code or a Python print of a dict.
Fix: replace single quotes with double quotes. Beware of apostrophes inside values, which need no change in double-quoted strings.
3. Unquoted keys
{ name: "Ada" }
Every key must be a double-quoted string, with no exceptions.
Fix: wrap the key: "name".
4. Missing comma between items
{
"name": "Ada"
"age": 36
}
The parser reads "name": "Ada" and then meets another string where it expects a comma or closing brace. The reported position is the start of the next item, so look just before it.
Fix: add a comma after the previous value.
5. Comments
{
// user record
"name": "Ada"
}
JSON has no comment syntax. Config formats such as JSONC and JSON5 allow them, but a strict parser will not.
Fix: delete the comments. If you need annotations, add a field like "_comment": "...", or use a format that supports comments.
6. Unescaped characters in strings
{ "path": "C:\Users\ada", "quote": "She said "hi"" }
Inside a string, a backslash begins an escape sequence and a bare double quote ends the string. Raw line breaks and tabs are not allowed either.
Fix: escape them: \\ for a backslash, \" for a quote, \n for a newline, \t for a tab.
{ "path": "C:\\Users\\ada", "quote": "She said \"hi\"" }
7. Invalid values: undefined, NaN, Infinity
{ "score": NaN, "extra": undefined }
JSON has exactly six value types: object, array, string, number, true/false, and null. undefined, NaN and Infinity do not exist.
Fix: use null for absent or invalid values, or omit the key. If the data comes from JSON.stringify, it already drops undefined and writes NaN as null, so check the producer.
8. Wrong number format
{ "a": 012, "b": .5, "c": +1, "d": 0x1F }
Numbers cannot have leading zeros, a bare decimal point, a plus sign or hexadecimal notation.
Fix: write 12, 0.5, 1 and 31. If leading zeros matter, such as a zip code, make it a string: "02134".
9. Mismatched or missing brackets
{ "users": [ { "name": "Ada" }, { "name": "Grace" } }
Every { needs a } and every [ needs a ], closed in the opposite order. The parser usually fails at the end of the document with Unexpected end of JSON input, or at the first closer that does not match.
Fix: count and match. A formatter that indents the document makes the mismatch obvious because the structure visibly stops lining up.
10. Truncated or copied-wrong data
Unexpected end of JSON input often does not mean you made a typo. It means the text stopped early. Typical causes:
- Postman or a terminal truncated a large response.
- A copy from a log line missed the last characters.
- An API timed out and returned a partial body.
Fix: re-copy the full response, or save it to a file and open that instead. See how to view large JSON files.
Other causes worth checking
A byte order mark (BOM). A file saved as “UTF-8 with BOM” begins with an invisible character, which some parsers reject with Unexpected token at position 0. Re-save as plain UTF-8.
Several documents in one file. Two objects side by side, {...}{...} or one per line, is not valid JSON. If it is one per line, it is JSON Lines, which is valid as a format of its own, and the JSON to Table tool reads it.
HTML instead of JSON. If the error is Unexpected token <, you were sent an HTML page, usually a login screen or error page. Check the status code and the URL.
Duplicate keys. {"a":1,"a":2} is technically permitted, but parsers keep only one value, and which one is not guaranteed. Remove duplicates.
Data that is JSON in a string. If you see \" everywhere and the whole thing is wrapped in quotes, it has been encoded twice. Parse it once to get the string, then parse again.
Reading error messages
| Message | Usual cause |
|---|---|
Unexpected token } ... |
Trailing comma before the brace |
Unexpected token ' ... |
Single quotes |
Unexpected token < ... |
HTML returned instead of JSON |
Unexpected end of JSON input |
Truncated text or missing closing bracket |
Expected property name or '}' |
Unquoted key or trailing comma |
Unexpected non-whitespace character after JSON |
Extra content after the document |
Avoiding errors in the first place
- Never write JSON by hand if a program can generate it; use
JSON.stringify,json.dumps, or an equivalent. - Format and validate before committing config files.
- Validate API payloads against a schema, and generate types from a sample with JSON to TypeScript.
If the document is valid and you need to inspect or compare it, see how to compare two JSON files.