Why your JSON is invalid (and how to fix it fast)
The usual reasons JSON won't parse (trailing commas, smart quotes, single quotes, missing brackets) and how to spot and fix each one in seconds.
Software engineer and technical writer
If you have ever pasted some JSON into a parser and gotten back a flat Unexpected token or Invalid JSON, you already know the frustrating part: the message rarely tells you what is actually wrong. The good news is that the overwhelming majority of invalid JSON comes down to about six mistakes. Once you can recognize them, most "broken" JSON takes seconds to fix.
Here is the quick way to find the problem, followed by the specific causes and how to fix each one.
The fastest fix: format it and read the first error
Before you scan the whole document by eye, paste it into a formatter. A formatter re-indents the structure and stops at the first thing it can't parse, usually with a line and column number. That single pointer is almost always enough to identify the mistake.
Fix the first error it reports, run it again, and repeat. Errors often cascade, so one real mistake near the top can make everything below it look broken too. Work top-down and the rest frequently resolves itself.
The usual causes, and how to fix them
1. A trailing comma
This is the single most common cause. JSON does not allow a comma after the last item in an object or array, even though JavaScript and JSON5 do.
{
"name": "Ada",
"role": "engineer",
}
That comma after "engineer" is invalid. Remove it:
{
"name": "Ada",
"role": "engineer"
}
2. Single quotes instead of double quotes
JSON requires straight double quotes for both keys and string values. Single quotes are a JavaScript habit that JSON does not accept.
{ 'name': 'Ada' }
Should be:
{ "name": "Ada" }
3. Smart quotes and fancy dashes from a document
When you copy text out of a word processor, a slide, or a chat app, straight quotes (") are often silently replaced with curly "smart quotes" (“ ”), and hyphens with en or em dashes. They look almost identical but JSON rejects them. If your JSON looks correct and still won't parse, this is a likely culprit. Retype the quotes, or run the text through a formatter that normalizes them.
4. A missing or mismatched bracket
Every { needs a matching } and every [ needs a matching ]. A single missing bracket, often at the very end after editing, invalidates the whole document. Formatting the text makes this obvious, because the indentation will not close back to the left margin.
5. Unquoted keys
In JavaScript you can write { name: "Ada" }. In JSON the key must be quoted: { "name": "Ada" }. Every key is a double-quoted string, with no exceptions.
6. Comments
JSON has no comments. // and / ... / are valid in JavaScript and in some config dialects, but a strict JSON parser will reject them. Remove comments before parsing, or keep them in a separate file.
A quick mental checklist
When something won't parse and you want to eyeball it, scan for these in order:
- Trailing comma before a
}or] - Single quotes anywhere
- Curly quotes or fancy dashes from pasted text
- An unclosed
{,},[, or] - An unquoted key
- A stray comment
That list catches almost everything. For anything stubborn, the formatter's line-and-column pointer will take you straight to it.
After it's valid
Once your JSON parses cleanly, you often want to do something with it: pretty-print it for a code review, minify it for a payload, or pull it into a spreadsheet. If you need it in tabular form, converting valid JSON to CSV is a common next step and avoids hand-copying nested values.
Valid JSON is mostly about discipline with quotes, commas, and brackets. Keep the checklist above in mind and the cryptic parser errors stop being a mystery.
Key takeaways
- Most invalid JSON comes from one of six things: a trailing comma, single
quotes, smart quotes from pasted text, a missing bracket, an unquoted key, or a comment.
- JSON requires straight double quotes on every key and every string value.
- JSON allows no comments and no trailing commas, even though JavaScript does.
- The fastest fix is to run the text through a formatter, which points to the
line and column of the first error.
- Errors cascade, so fix the topmost error first and re-validate.
This article was prepared with AI-assisted drafting and reviewed by a human editor for accuracy, clarity, and relevance.
Frequently asked questions
Are trailing commas ever allowed in JSON?+
No. The JSON specification does not permit a comma after the last element of an array or object. JSON5 and JavaScript object literals allow them, which is why the habit slips in, but a strict JSON parser will reject it.
Why does my JSON break when I copy it from a document?+
Word processors and chat apps often replace straight quotes with curly “smart quotes” and hyphens with en/em dashes. JSON only accepts straight double quotes, so the pasted text fails to parse until you convert them back.
Can JSON keys use single quotes?+
No. Both keys and string values must use straight double quotes. Single quotes are valid in JavaScript but not in JSON.
What is the fastest way to find the exact error?+
Paste the text into a formatter that points to the line and column of the first problem. Fixing that one spot and re-validating is faster than re-reading the whole document.