Trailing Commas in JSON: Find and Fix Them

A comma separates JSON items; it cannot follow the final item. See invalid and corrected object and array examples.

A trailing comma is a comma after the last member of an object or the last item of an array. Strict JSON does not allow it. Remove that comma while keeping commas between items.

A trailing comma in an object

This input is invalid:

{
  "name": "Alex",
  "active": true,
}

The comma after true tells the parser another property follows. Instead, the parser finds a closing brace. Depending on the parser, the error may mention an expected property name, a string, or an unexpected }.

The corrected object is:

{
  "name": "Alex",
  "active": true
}

The comma after "Alex" stays because another property follows it.

A trailing comma in an array

Invalid:

["design", "build", "test",]

Corrected:

["design", "build", "test"]

Do not replace a trailing comma with null unless you actually intend to add another array item. [1, 2, null] is valid, but it contains three values instead of two.

Why did it work in JavaScript?

JavaScript object and array literals allow some syntax that JSON does not. Code copied from a JavaScript source file might contain trailing commas, single-quoted strings, comments, or unquoted property names. An HTTP endpoint expecting JSON may reject that text even though it is valid JavaScript.

JSON5 and some JSONC implementations also permit additional syntax. Always check which format the consumer expects. This validator uses strict JSON.

Fix the document without changing its values

  1. Open the input in the JSON validator.
  2. Select the reported error to jump to its position.
  3. Check immediately before the closing } or ] for an extra comma.
  4. Remove that comma and validate again.

Avoid a simple global search-and-replace for commas before brackets. The same characters can occur inside strings, such as "keep this ,] text". Removing them would change the value. A syntax-aware repair tool would need to distinguish strings from structural punctuation.

The formatter leaves invalid input unchanged. Once the syntax is valid, formatting can make any remaining nesting easier to inspect.

Reference: RFC 8259, where commas separate members or values within their respective grammar rules.

Already have valid JSON? Make it readable