JSON Trailing Comma Error
JSON syntax does not allow a comma after the last element in an object or array. Many languages do, but JSON spec does not.
Common causes
- Copy-pasting from JavaScript or other languages that allow trailing commas.
- Adding a new property and leaving a comma after the previous last one.
How to fix
- Remove the comma after the last property or array element.
- Use a linter or validator that flags trailing commas.
- Validate your JSON online to get the exact line.
Examples
Bad
[1, 2, 3,]
Good
[1, 2, 3]
FAQ
- Why does JSON not allow trailing commas?
- The JSON spec was designed to be minimal; trailing commas were omitted to avoid ambiguity.
- Does JavaScript JSON.parse allow trailing commas?
- No. Standard JSON does not; only JavaScript object literals can have trailing commas.
Fix it now
Try in validator (prefill this example)