How to fix trailing commas in JSON
A comma after the last property in an object or the last item in an array makes strict JSON invalid. Remove that final comma before } or ], keeping the commas between items.
Fix a broken example in your browser
Load a small example with two trailing commas, then choose Fix My JSON. Or open the validator and paste your own document. JSON validation and repair run on your device; the tool does not upload your pasted JSON for processing.
Trailing comma in a JSON object
In the first example, the comma after 3 promises another property, but the object ends instead. Delete that comma. The comma after "Demo" must stay because another property follows it.
Invalid — comma after the last value
{
"name": "Demo",
"retries": 3,
}Valid JSON
{
"name": "Demo",
"retries": 3
}Trailing comma in a JSON array
Arrays follow the same rule. The last item needs no separator after it. Check nested arrays and objects too: removing one outer comma will not fix a second trailing comma inside a nested list.
Invalid array
["red", "green", "blue",]Valid array
["red", "green", "blue"]Why does JSON.parse reject it?
JavaScript object and array literals can allow trailing commas, but JSON is a stricter data format. A snippet that works in a JavaScript source file can therefore fail when pasted into a JSON API request or a package.json file. JSON5 and some configuration parsers use different rules; a strict JSON endpoint still needs strict JSON.
Depending on your browser or runtime, you may see an error such as Unexpected token or Expected double-quoted property name. These messages are not unique to trailing commas. Inspect the characters just before the reported closing bracket or brace, then validate again.
Fix the punctuation without changing your data
- Find the final property or array item before the closing delimiter.
- Remove only its trailing comma. Keep separators between other entries.
- Check nested containers, then validate the full document.
- If you use automatic repair, review the result before sending it to an API or replacing a configuration file.
Do not remove every comma or blindly replace every ,} sequence: that sequence can be part of a quoted string, where it is valid data. For example, {"note": "keep ,} exactly"} is already valid JSON.
The repair tool can correct other syntax issues too. It cannot know whether a missing item was accidentally deleted, so review inferred repairs. If you are generating JSON in JavaScript, use JSON.stringify(value) instead of joining strings and adding separators by hand.