Trailing Commas in JSON: Why They Break Everything
Add a comma after the last item in a JSON array or object and your parser throws an error. No warning, no fallback — just a hard failure. Here's why JSON is strict about this and what to do about it.
Why JSON forbids trailing commas
The JSON specification (RFC 8259) was designed to be simple and unambiguous. Its grammar only allows a comma between values — not after the last one. This was a deliberate choice to keep parsers minimal.
// ❌ Invalid JSON — trailing comma
{
"name": "Alice",
"role": "admin",
}
// ✅ Valid JSON
{
"name": "Alice",
"role": "admin"
}
The same rule applies to arrays:
// ❌ Invalid
["a", "b", "c",]
// ✅ Valid
["a", "b", "c"]
The error message you'll see
Most parsers report something like:
SyntaxError: Unexpected token } in JSON at position 42
JSON parse error: trailing comma
The position number points to the closing bracket, not the actual comma — which makes it harder to spot.
Where trailing commas sneak in
The most common source: copying from JavaScript object literals or TypeScript configs, where trailing commas are valid (and often enforced by linters). VS Code and ESLint treat them as style preferences in JS, so they feel harmless — until the value goes into a .json file.
Another source: editing a list and deleting the last item without removing the now-trailing comma from the item above it.
How to fix it
Quick fix: paste your JSON into the JSON formatter and validator. It highlights the exact line with the error and shows a cleaned-up version you can copy back.
In editors: VS Code underlines trailing commas in .json files when strict validation is enabled — it's on by default.
In code: use JSON.stringify() in JavaScript or your language's built-in serializer — these never produce trailing commas.
JSON5 and JSONC do allow trailing commas
If you need comments and trailing commas in config files, look at JSON5 (*.json5) or JSONC (*.jsonc). Both are supersets of JSON that relax these restrictions. See the comparison in JSON5 vs JSONC.
For a full rundown of what else trips up JSON parsers, see common JSON syntax errors.
Got a config file to check?
Open the config toolkit →