</>
ValidateHTML

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

Invalid JSON
{
  "name": "Alice",
  "age": 25,
  "hobbies": [
    "reading",
    "coding",
  ],
}
Valid JSON
{
  "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?
Trailing commas were added to JavaScript to make diffs and reordering cleaner. JSON, defined by RFC 8259, deliberately keeps a minimal grammar for portability across languages, so it forbids any comma that is not between two values.
Is a trailing comma ever valid in JSON?
No. A comma may only separate two values in an array or two members in an object. A comma immediately before a closing } or ] is always a parse error in standard JSON.
How do I allow trailing commas in my config files?
Use JSONC or JSON5 instead of strict JSON. VS Code settings and tsconfig.json accept JSONC. But a file parsed by JSON.parse or a standard API must have no trailing commas.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · 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

Start free trial

Related JSON Errors

View all JSON errors