Developer guide

Fix trailing commas in JSON

JSON does not allow a comma after the final item in an object or array, even though many JavaScript examples do.

Open JSON Validator View all tools

The problem

Trailing commas are easy to miss in config files, copied snippets, and hand-edited API payloads.

Example

Input

{
  "name": "1024base",
  "private": true,
}

Output

{
  "name": "1024base",
  "private": true
}

How to fix it

  1. Find the last property in each object and the last value in each array.
  2. Remove the comma when there is no next item after it.
  3. Validate after each cleanup if the payload is large, because one trailing comma can hide the next syntax issue.

Why this one is easy to miss

Trailing commas look harmless because many code editors accept them in JavaScript, TypeScript, and config-like examples. JSON is stricter, so the same snippet can fail when it reaches an API or a database field.

When cleaning a large payload, search for comma-plus-closing-bracket patterns after deleting fields. It is faster than reading every line from top to bottom.

Common mistakes

  • Comma before a closing curly brace
  • Comma before a closing square bracket
  • Copying from JavaScript or TypeScript where trailing commas are accepted
  • Leaving a comma after deleting the last property

Related problems

FAQ

Why does JavaScript allow this but JSON does not?

JavaScript object literals and JSON are different formats. JSON keeps a stricter grammar for data exchange.

Can a formatter remove trailing commas automatically?

A strict JSON formatter cannot parse invalid JSON first. Remove the trailing comma, then format the result.

Are trailing commas allowed in arrays?

No. JSON arrays also reject a comma after the final value.