JSON Trailing Comma Error, Explained
JSON does not allow a comma after the last element of an object or array. It's a strict, deliberate part of the spec — not a parser bug.
What triggers it
{
"name": "Ada",
"role": "admin",
}
That trailing comma after "admin" is invalid. The same applies to arrays: [1, 2, 3,] fails to parse.
Why JSON is stricter than JavaScript here
JavaScript object and array literals do allow a trailing comma — it was added specifically so version control diffs stay clean when you add a new last item. JSON, defined independently as a data interchange format (RFC 8259), never adopted that allowance. The two look similar but are governed by different grammars, and this is the most common place the difference bites people who write JSON by hand or generate it with string templates.
How to avoid it
- If you're generating JSON programmatically, use your language's JSON serializer (
JSON.stringify,json.dumps, etc.) instead of building strings by hand — it will never emit a trailing comma. - If you're hand-editing JSON, most editors' bracket-matching or a linter will flag it before you save.
- If you've already got broken JSON with trailing commas (or single quotes, comments, unquoted keys), paste it into JSON Repair to fix it in one click.