Trailing Comma in JSON
A trailing comma is a comma placed after the last property in an object or the last element in an array. JavaScript and many programming languages allow this, but JSON strictly forbids it. The parser sees the comma and expects another value, but finds a closing bracket instead.
Why It Matters
The JSON document fails to parse entirely. This is especially common when developers copy JavaScript objects into JSON files without cleaning up the syntax, or when removing the last property and forgetting to also remove its preceding comma.
Common Causes
- Copying a JavaScript or Python object into JSON, where trailing commas are legal, without cleaning the syntax.
- Deleting the last property or array element but leaving the comma that preceded it.
- Reordering properties and ending up with a comma right before the closing brace or bracket.
Code Examples
{
"name": "Alice",
"age": 25,
"hobbies": [
"reading",
"coding",
],
}{
"name": "Alice",
"age": 25,
"hobbies": [
"reading",
"coding"
]
}How to Fix
- 1Remove the comma after the last property in every object.
- 2Remove the comma after the last element in every array.
- 3Check nested structures carefully. Trailing commas often hide inside deeply nested objects.
- 4Use a JSON validator to spot trailing commas automatically before deploying.
Frequently Asked Questions
Why does JavaScript allow trailing commas but JSON does not?
Is a trailing comma ever valid in JSON?
How do I allow trailing commas in my config files?
Check Your JSON Now
Our JSON validator detects this error automatically and shows the exact line and column.
Open JSON ValidatorCloudways · Managed Cloud Hosting
Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related JSON Errors
Unexpected Token in JSON
Fix the unexpected token error in JSON fast. See why parsers fail on trailing commas, single quotes, unquoted keys, and comments, with clear examples.
Missing Comma Between Properties
Fix the missing comma error in JSON the right way. Every key-value pair and array element must be separated by a comma, and our examples show where.
Unquoted Property Keys in JSON
JSON requires every property name wrapped in double quotes, so bare keys fail. Learn how to fix unquoted key errors when converting JavaScript objects.