Common JSON Errors and How to Fix Them
JSON parsers fail loudly and with very little sympathy. The good news is that almost every error comes from one of a dozen causes. This guide maps the message you see to the thing that is actually wrong.
How to read a parse error
Most parsers report a character offset or a line and column. That location is where the parser gave up, not necessarily where the mistake is: a missing closing brace is usually reported at the end of the file. Always look upward from the reported position.
Unexpected token < in JSON at position 0
This is the most reported JSON error and it is almost never a JSON problem. A request expected JSON but received HTML — typically a 404 page, a login redirect, a proxy error page or a framework stack trace. Open the network tab, look at the raw response body and the status code, and fix the request or the endpoint.
Check the Content-Type response header. If it says text/html, the server never intended to send JSON.
Trailing commas
{
"a": 1,
"b": 2,
}{
"a": 1,
"b": 2
}JavaScript, TypeScript and Python all tolerate trailing commas, so they slip in constantly when JSON is hand-edited. JSON does not allow them anywhere.
Quote problems
- Single quotes: 'value' must be "value"
- Smart quotes: “value” from a word processor or chat app looks identical but is a different character
- Unquoted keys: { key: 1 } must be { "key": 1 }
- Unterminated string: a missing closing quote makes the parser swallow the rest of the file
Curly/smart quotes are the hardest to spot because they render almost identically. If a line looks correct but still fails, retype the quotes by hand.
Escaping mistakes
{
"path": "C:\\Users\\ada\\data.json",
"quote": "She said \"hello\"",
"newline": "line one\nline two"
}A literal newline or tab inside a string is invalid — control characters must be escaped as \n, \t, \r and so on. This trips people up when a multi-line value is pasted directly into a string.
Encoding and invisible characters
- A UTF-8 byte-order mark (BOM) at the start of a file makes strict parsers fail at position 0 — save the file as UTF-8 without BOM
- Non-breaking spaces copied from web pages are not valid whitespace in JSON
- Files saved as UTF-16 will not parse as JSON; convert to UTF-8
Structural mistakes
Unbalanced braces or brackets
Format the document: a formatter reports the exact point where nesting breaks, and correct nesting becomes visible after indentation.
Two documents in one file
{...}{...} is not valid. Wrap the objects in an array, or emit one object per line as NDJSON and parse line by line.
Duplicate keys
Technically permitted by the spec, but parsers keep only one value — usually the last. Deduplicate before it causes a silent data loss bug.
undefined, NaN or Infinity
These come from JavaScript and Python serialisers. Replace with null, or a sentinel value your consumer understands.
A repeatable debugging routine
Find and fix an invalid JSON document
- 1
Confirm it is really JSON
Check the first characters. A leading < means HTML, a leading BOM means an encoding issue.
- 2
Run a validator
Get the exact line and column of the first failure rather than guessing.
- 3
Look upward from the error
Missing closing tokens are always reported later than the real mistake.
- 4
Format the document
Indentation makes unbalanced nesting obvious at a glance.
- 5
Re-validate
Repeat until clean — one syntax error commonly masks another.
- 6
Add validation upstream
If the file is machine-generated, fix the producer so the same class of error cannot return.
JSON Validator
Get line-and-column error reporting on your document, entirely in the browser.
Frequently asked questions
What does "Unexpected end of JSON input" mean?
The document ended while the parser was still expecting something — usually a missing closing brace or bracket, or a truncated response body.
Are duplicate keys allowed in JSON?
The specification permits them but leaves behaviour undefined. Most parsers keep the last occurrence, so treat duplicates as a bug.
Can comments be added to JSON?
No. Use a "_comment" field, or a superset like JSONC or YAML if your tooling supports it.
Why does my JSON work in JavaScript but fail in a validator?
You are almost certainly using a JavaScript object literal — unquoted keys, single quotes or trailing commas — rather than JSON.
Put this into practice
JSON Validator runs entirely in your browser — no upload, no account, no limits.
Open JSON ValidatorRelated tools
Related guides
How to Format JSON (Beautify, Indent and Minify)
Learn how JSON formatting works, see a before-and-after example, fix the errors that block beautifying, and format JSON online in your browser without uploading a file.
What Is JSON? A Plain-English Guide
JSON explained without jargon: what it is, how the syntax works, which data types it supports, where it is used and how it differs from JavaScript objects.
Base64 Explained: What It Is and When to Use It
How Base64 turns binary into text, why output is about 33% larger, where padding comes from, URL-safe variants, and why Base64 is encoding rather than encryption.
JSON vs XML: Which Format Should You Use?
A practical JSON vs XML comparison: syntax, size, parsing speed, schemas, comments, attributes and metadata — plus clear guidance on which format fits which job.
JWT Explained: Structure, Claims and Safe Use
What a JSON Web Token contains, how the three segments work, which claims matter, how signatures are verified and the mistakes that turn JWTs into a security hole.
URL Encoding Explained (Percent-Encoding)
Why URLs need encoding, which characters are reserved, the difference between encodeURI and encodeURIComponent, plus and space confusion, and how to avoid double encoding.