The short answer
Most JSON errors come from six mistakes: a trailing comma, single quotes, unquoted keys, comments, a missing comma, or receiving something that isn't JSON at all (an HTML error page, an empty response or undefined). Paste the text into a JSON validator to get the exact line and column, then use the table below to match the message to its cause.
JSON is strict on purpose. It looks like JavaScript, but it accepts far less: no comments, no trailing commas, no single quotes, no undefined or NaN. Anything written by hand — a config file, an API request body, test data — trips over one of these sooner or later.
The frustrating part is the error message, which usually points at the character after the real mistake and is worded differently in every language. Below are the actual messages from JavaScript (Chrome, Edge and Node.js all use the same engine) and Python, mapped to what went wrong.
On this page
Error message lookup table
| Cause | JavaScript says | Python says |
|---|---|---|
| Trailing comma in an object | Expected double-quoted property name | Expecting property name enclosed in double quotes |
| Trailing comma in an array | Unexpected token ']' | Expecting value |
| Single quotes or unquoted key | Expected property name or '}' | Expecting property name enclosed in double quotes |
| Missing comma, or a comment | Expected ',' or '}' after property value | Expecting ',' delimiter |
| Empty string or empty response | Unexpected end of JSON input | Expecting value: line 1 column 1 (char 0) |
| Got an HTML page instead | Unexpected token '<', "<!DOCTYPE "... | Expecting value: line 1 column 1 (char 0) |
| Parsing the value undefined | "undefined" is not valid JSON | — |
| Invisible byte-order mark (BOM) | Unexpected token '' | Unexpected UTF-8 BOM |
| NaN or Infinity | Unexpected token 'N' | Accepted (see below) |
| Raw tab or line break inside a string | Bad control character in string literal | Invalid control character |
JavaScript messages also include a position, like at position 7 (line 1 column 8). Python adds line 1 column 8 (char 7). Newer Python versions word a few of these differently, but the causes are the same.
1. Trailing commas
The single most common JSON error, because JavaScript, Python and most config formats allow it and JSON doesn't:
{
"name": "Ada",
"role": "admin", ← this comma is the problem
}Notice that the error points at the closing }, not the comma. The parser saw a comma, expected another property, and found the end instead. Whenever an error points at a closing bracket, look one character back.
2. Single quotes and unquoted keys
JSON strings and keys must use double quotes. {'name': 'Ada'} and {name: "Ada"} are valid JavaScript objects but invalid JSON.
This usually happens when someone copies an object from code or prints a Python dictionary with print(data) or str(data) — that produces Python syntax with single quotes. Use json.dumps(data) in Python, or JSON.stringify(data) in JavaScript, to get real JSON.
4. The response isn't JSON at all
When code calls an API and then parses the response, the most confusing errors aren't about JSON syntax — the server sent something else:
Unexpected token '<'means the response starts with<— almost always an HTML page: a 404, a server error, or a login page because your session expired.Unexpected end of JSON inputmeans the body was empty, which is normal for a204 No Contentresponse or a request that failed silently."undefined" is not valid JSONmeans you passedundefined— often from readinglocalStorageor a property that doesn't exist.
- 1Check the HTTP status code before parsing.
- 2Check the
Content-Typeheader isapplication/json. - 3Log the first couple of hundred characters of the raw text — you'll see at once whether it's HTML or empty.
5. NaN, Infinity and very large numbers
Here's a trap that catches teams with a Python backend and a JavaScript frontend. Python's json module writes NaN and Infinity by default:
json.dumps({"score": float("nan")}) → {"score": NaN}That isn't valid JSON, and JSON.parse in the browser rejects it with Unexpected token 'N'. Pass allow_nan=False to json.dumps to catch it on the server, and send null instead.
Large IDs can change silently
JSON allows numbers of any size, but JavaScript stores numbers as 64-bit floats and loses precision above 9,007,199,254,740,991. A database ID like9007199254740993 parses without an error — as a different number. Send large IDs as strings.6. Invisible characters
When the JSON looks perfect and still fails, suspect something you can't see:
- A byte-order mark at the very start, added by some Windows editors. Save the file as “UTF-8” rather than “UTF-8 with BOM”, or in Python read it with
encoding="utf-8-sig". - Smart quotes —
“and”instead of"— from text pasted out of a word processor or chat app. - Real tabs or line breaks inside a string. Inside JSON strings they must be written as
\tand\n.
Finding the error fast
- 1Paste the text into the JSON formatter. It shows the line and column of the first problem.
- 2Look at that spot and one character before it — the cause is usually just before where the parser gave up.
- 3Fix it and check again; there may be a second mistake further down.
- 4Once it's valid, format it with indentation so the next mistake is easier to spot.
If you have a working version and a broken one, format both with sorted keys and compare them with Text Compare to see exactly what changed.
Frequently asked questions
What does 'Unexpected token < in JSON at position 0' mean?
The text starts with <, so it's HTML, not JSON — usually an error page, a 404, or a login page returned by the server. Check the URL, the status code and whether you're still signed in.
Why are trailing commas not allowed in JSON?
JSON was defined as a small, strict subset of JavaScript object syntax in the early 2000s, before trailing commas were common, and the standard was deliberately frozen so every parser behaves the same.
Can JSON have comments?
No. Some tools accept a relaxed variant (JSONC or JSON5) that allows them, but standard parsers reject comments.
How do I fix 'Unexpected end of JSON input'?
The text you parsed was empty or cut off. Check that the request succeeded and returned a body, and that you're not parsing a partially downloaded or truncated file.
Is null valid JSON?
Yes. null, true, false, numbers, strings, arrays and objects are all valid. undefined, NaN and Infinity are not.
OnlineToolPro Editorial Team
Builds and tests the tools on this site
The team behind OnlineToolPro. We write guides from building and testing these tools, and check platform rules against official documentation such as YouTube Help. When something changes, we update the article and its date.
3. Comments
Standard JSON has no comments at all — neither
// linenor/* block */. Some files look like JSON and allow them anyway: VS Code settings andtsconfig.jsonuse a relaxed format often called JSONC. Copy one of those into a strict parser and it fails.Remove the comments, or move the information into a real field such as
"_note": "..."if you need to keep it.