JavaScript lets you write trailing commas. JSON does not. That single difference is behind an enormous share of parse errors, because most of us write JSON the way we write JavaScript objects and only discover the distinction when the parser complains. The error message, usually "Unexpected token } in JSON at position N," points at the closing bracket rather than the comma, which is why the offending line looks innocent.
What it looks like
{
"name": "Ada",
"role": "engineer",
}
That comma after "engineer" is illegal in JSON. The same rule applies to arrays: [1, 2, 3,] fails just as hard. The fix is a single keystroke: delete the comma before the closing bracket.
Why it keeps happening
The classic trigger is deleting the last item in a list. You remove the line but leave the comma on what is now the last line. Editors with JavaScript formatting habits make it worse: formatters configured for JavaScript will happily add trailing commas, and copy-pasting a JavaScript object literal into a .json file carries them over silently. The JSON spec, RFC 8259, froze the grammar without them, and parsers enforce it.
Stop it permanently
A JSON-aware linter in your editor flags trailing commas as you type, which is the cheapest fix. If you use Prettier, set the trailing-comma option to "none" for JSON files so your formatter stops adding them on save. For config files where you genuinely want comments and trailing commas, stop pretending the file is strict JSON and use JSONC or JSON5 instead. And if you are generating JSON from an LLM, assume the output will contain trailing commas: strip any comma followed only by whitespace and then a closing bracket before parsing, taking care not to touch commas inside string values.
Paste your broken JSON into the repair tool and it will fix the trailing commas and show you exactly what it changed.
Frequently asked questions
Is a trailing comma valid in JSON?
No. The JSON grammar in RFC 8259 does not allow a comma after the last member of an object or the last element of an array. JSON.parse in every language rejects it.
Why does JavaScript allow trailing commas but JSON does not?
JSON is a data interchange format with a frozen grammar, deliberately stricter than any programming language. JavaScript object literals are code, and the language added trailing commas as a convenience for cleaner diffs. The two look alike but follow different rules.
What does "Unexpected token } in JSON" mean?
The parser hit a closing bracket where it expected another value, which almost always means a stray comma sits right before that bracket. Look one line above the reported position for a comma with nothing after it.
How do I find a trailing comma in a large file?
Use a JSON linter, which highlights the exact spot. As a quick manual check, search for a comma followed by optional whitespace and then a closing brace or bracket, while ignoring matches inside string values.
Get one practical dev-tools guide a week: subscribe to the newsletter for new JSON guides and parser explainers.
Related reading: Why Is My JSON Invalid? The 7 Syntax Errors That Break JSON.parse · JSON with Comments (JSONC): What It Is and How to Handle It · NDJSON Broke My Parser: How to Fix JSON Lines Errors