All Articles
Text

Fix a JSON Trailing Comma Without Changing the Data

November 10, 20263 min read

A trailing comma is a comma after the last item in an object or array, like "active": true, right before the closing }. JavaScript code often allows it, but JSON does not. Delete that one comma and the document parses again; the data does not change.

JSON Formatter with a four-line object whose active line ends in a comma; the red JSON Parse Error says Expected double-quoted property name in JSON at position 38, line 4 column 1, and Formatted Output is empty
The error points at the closing brace on line 4, the first place the parser gives up. Open the JSON Formatter.

Find and fix it

  1. Paste this into Input JSON:
    {
      "name": "Mina",
      "active": true,
    }
  2. A red JSON Parse Error box appears above the editor and Formatted Output stays empty. There is no Format button: the check runs as you type.
  3. Read the line and column at the bottom of the box. Here it says Line 4, Column 1, which is the closing }. The comma is on the line above, at the end of line 3. The parser only notices when it reaches the brace.
  4. Delete the comma after true. The red box disappears and the cleaned-up JSON appears under Formatted Output.
JSON Formatter after the trailing comma is removed: no error box, Input JSON on the left and the same four lines, indented with two spaces, under Formatted Output on the right
After deleting the comma, the error is gone and the output panel fills in.

Keep the comma between items ("name": "Mina",). Only the comma directly before a closing } or ] has to go.

Arrays work the same way

[1,2,3,] is invalid for the same reason. In the Chrome version used for these screenshots the message for an array is shorter: Unexpected token ']' with a short quote of the text around it and no line or column. In that case, look at the end of the text it quotes and find the comma just before the ].

Check the data afterwards

  • Removing the comma only changes punctuation. true stays true and numbers stay numbers, so compare the Formatted Output with what you expected.
  • If you edit a config file, keep a copy of the original before you paste the corrected version back.
  • Valid JSON is not the same as correct data. See what the JSON Formatter does and does not check.

If it doesn't work

  • A different error appears after you remove the comma: the first error was hiding the next one. The tool reports only one problem at a time, so fix them one by one.
  • The line number looks wrong: as above, it is often the line after the real mistake.
  • The message wording differs from the screenshot: error text comes from your browser and varies between Chrome, Firefox and Safari. The mistake it points at is the same.
  • The commas are inside a JavaScript file: only copy the JSON part. Code around it (const x =, a trailing ;) is not JSON.

Your JSON is checked in your browser and is not uploaded. Open the free JSON Formatter.

jsontrailing commajson error