You are deep in a coding session, building a beautiful application or fetching data from an API, when suddenly everything stops. Your console shows: SyntaxError: Unexpected token }. You stare at your JSON, and it looks fine. But somewhere in there — possibly at the very end of an object or array — is a single trailing comma. And JSON has zero tolerance for it.
Why Trailing Commas Break JSON
JSON follows the ECMA-404 specification, in which commas act strictly as separators between values — not terminators. When a comma appears after the final item, the parser expects another value to follow. Finding a closing brace instead is a specification violation, and the parser throws an error immediately.
This is a common frustration for developers who switch between JavaScript and JSON. Modern JavaScript (ES2017+) allows trailing commas in objects and function parameters, so the habit carries over. But JSON never updated the same way — it remains strict by design to ensure consistent parsing across every language.
In Objects
// ❌ Invalid — trailing comma after last property
{
"username": "DevExplorer",
"points": 500,
"active": true,
}
// ✅ Valid — no comma after last property
{
"username": "DevExplorer",
"points": 500,
"active": true
}
In Arrays
// ❌ Invalid — trailing comma after last item
["apple", "orange", "banana",]
// ✅ Valid
["apple", "orange", "banana"]
Nested Structures
The mistake is even easier to make in nested structures because each closing brace or bracket looks like a natural stopping point. Always check the last item before every } and ].
// ❌ Invalid — trailing comma inside nested object
{
"user": {
"name": "Alex",
"roles": ["admin", "editor",], ← trailing comma in array
}, ← trailing comma in object
"active": true
}
How to Find Trailing Commas Fast
In small JSON files, a visual scan is enough. For large API payloads, searching manually is painful and unreliable. The fastest approach is to paste your JSON into our JSON Validator — it highlights the exact line where the error occurs.
- In VS Code, use the Prettier extension — it auto-removes trailing commas when formatting JSON files.
- In any editor, search with the regex
,\s*[}\]]to find trailing commas before closing braces or brackets. - Set your editor to use
.jsonfile associations — most editors then lint JSON automatically and underline violations.
Prevention Tips
- Use a JSON linter in your code editor. VS Code, WebStorm, and most modern editors have built-in JSON validation.
- Auto-format your JSON using our beautifier — it re-structures JSON correctly, removing trailing commas in the process.
- Be careful when reordering properties. Moving the last item to a different position leaves a comma behind on what is now the new last item.
- Use
JSON.stringify()to generate JSON programmatically when possible — it never produces trailing commas.
JSON's strictness about trailing commas can feel unforgiving at first. But it is exactly that strictness that makes JSON reliable across every programming language and platform on earth. Once you train yourself to always check the last item in every object and array, this error disappears from your workflow entirely.
Find Trailing Commas Instantly
Paste your JSON into our free validator — it finds the exact line of the error in seconds.
Open JSON Validator