Illegal trailing comma before end of object
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.
{
"name": "Ada",
"roles": ["admin", "editor"],
}Line 3: delete ,.
{
"name": "Ada",
"roles": ["admin", "editor"]
}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.
- 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
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.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.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 quotesand point at the closing brace, one line below the comma you have to remove. For an array they sayExpecting value. It is the same document and the same fault. See Expecting property name for that message.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.dumpsdoes not write one.
Worth knowing
NoteJavaScript rejects the same comma. See Trailing comma in JSON.