Illegal trailing comma before end of object

ErrorPython

json.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 3 column 31 (char 49)

Where JSON.parse stops

  "name": "Ada",
  "roles": ["admin", "editor"],
}

What it means

The document has a comma right before a closing } or ]. JSON does not allow that. Python 3.13 and later says so and points at the comma. Earlier versions say something else and point at the closing brace.

Last verified on Python 3.9, 3.11, 3.12, 3.13 and 3.14.

The validator opens with the error marked. Examples travel in the URL fragment, which browsers never send to a server.

Express Lint lays broken JSON out by bracket depth and marks the line where it stops. It changes only spaces and line breaks outside strings. Strings in either quote stay as written. If the quotes do not pair up, it leaves your text as it is. Ctrl+Z undoes it. See how it works.

Usually
Illegal trailing comma before end of objectIllegal trailing comma before end of arrayPython 3.12 and earlier: a different messageWhere the comma came from
Fix
Delete the comma before the closing } or ].

The fix

Delete the comma before the closing } or ]. A comma goes between two items and never after the last one. On Python 3.13 and later the position is the comma. On earlier versions, look one line above the position.

broken.jsonFails to parse
{
  "name": "Ada",
  "roles": ["admin", "editor"],
}
JSON.parse stops at line 4, column 1.

Line 3: delete ,.

fixed.jsonParses
{
  "name": "Ada",
  "roles": ["admin", "editor"]
}
JSON.parse reads it.

How the message appears

CPython's json module reports line, column and character offset. The first line is Python 3.13 and 3.14 for the example. The second is what Python 3.9, 3.11 and 3.12 print for the same document. The last two are the same pair for an array. From 3.13 the position is the comma. Before that it is the closing brace or bracket.

Console
  • json.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 3 column 31 (char 49)
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 4 column 1 (char 51)
  • json.decoder.JSONDecodeError: Illegal trailing comma before end of array: line 2 column 30 (char 31)
  • json.decoder.JSONDecodeError: Expecting value: line 2 column 31 (char 32)

What causes it

  1. Illegal trailing comma before end of object

    The last key has a comma after it, and then comes the }. The comma says another key is coming and none does. In the example it is the comma after ["admin", "editor"]. Python 3.13 and 3.14 point straight at it, on line 3.

  2. Illegal trailing comma before end of array

    The same mistake in a list, like ["admin", "editor",]. From Python 3.13 the message names the array and points at the comma.

  3. Python 3.12 and earlier: a different message

    Older versions do not name the comma. For an object they say Expecting property name enclosed in double quotes and point at the closing brace, one line below the comma you have to remove. For an array they say Expecting value. It is the same document and the same fault. See Expecting property name for that message.

  4. Where the comma came from

    Python and JavaScript both allow a comma after the last item, so it gets copied into JSON. A config file where the last line was deleted leaves one behind, and so does a template that adds a comma after every row. json.dumps does not write one.

Worth knowing

NoteJavaScript rejects the same comma. See Trailing comma in JSON.

Your JSON and text are processed entirely in your browser and are never sent anywhere. To understand how the site is used we record each page view (the page, the referrer and an approximate location from your IP address) and keep it for 90 days. Nothing is stored on your device unless you choose it. Accept to also store a device identifier here and record your browser and device characteristics, which is what lets a return visit be told from a new one. Decline and nothing is sent at all. We respect Do Not Track. See our privacy policy.