Trailing comma in JSON: "Expected double-quoted property name"

A trailing comma is a comma after the last property of an object or the last item of an array. JavaScript, TypeScript and Python accept it, but strict JSON does not, so the parser expects another property or value and finds } or ] instead. The message points at the closing bracket; the comma to delete is just before it.

Seen as:

  • SyntaxError: Expected double-quoted property name in JSON at position 68 (line 5 column 1)
  • SyntaxError: Unexpected token ']', "[1, 2, 3,]" is not valid JSON
  • SyntaxError: Unexpected token } in JSON at position 68
  • SyntaxError: JSON.parse: expected double-quoted property name at line 5 column 1 of the JSON data
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 5 column 1 (char 68)

Input

Settings

History

Load from URL

Common causes

1. The last property was deleted or moved

Removing the final line of an object leaves the comma of the line above dangling. This is the most common source, especially in package.json and other hand-edited config.

Before
{
  "name": "pastekit",
  "private": true,
}
After
{
  "name": "pastekit",
  "private": true
}

2. A trailing comma at the end of an array

Lists that grow one line at a time often end with a comma. Chrome reports it as an unexpected ], Python 3.12 and earlier as “Expecting value”.

Before
{"allowedOrigins": ["https://example.com", "https://admin.example.com",]}
After
{"allowedOrigins": ["https://example.com", "https://admin.example.com"]}

3. Copied from JavaScript or a JSONC file

Code formatters such as Prettier add trailing commas to JavaScript objects, and JSONC files such as tsconfig.json and VS Code settings allow them. Pasting that text into a strict JSON parser fails. Use a JSONC or JSON5 parser for those files, or remove the commas.

Before
{
  "compilerOptions": {
    "strict": true,
    "target": "ES2022",
  },
}
After
{
  "compilerOptions": {
    "strict": true,
    "target": "ES2022"
  }
}

4. JSON built by a loop that appends ", " after every item

Templates and string-building loops that write a comma after each element leave one after the last. Let a serializer produce the text instead.

Before
items_json = "[" + "".join(f'"{sku}", ' for sku in skus) + "]"
After
items_json = json.dumps(skus)

Frequently asked questions

Why does JavaScript accept trailing commas but JSON does not?

JSON was frozen as a small subset of JavaScript syntax in the early 2000s, before trailing commas in object literals were standard. The JSON grammar has never changed, so they remain invalid in every compliant parser.

Which formats allow trailing commas?

JSON5 and JSONC (JSON with comments, used by tsconfig.json and VS Code) both allow them. YAML flow collections allow them as well. Plain JSON, JSON Lines and package.json do not.

What does Python 3.13 say about trailing commas?

Python 3.13 added a specific message, “Illegal trailing comma before end of object” (or “of array”), pointing at the comma itself. Earlier versions report “Expecting property name enclosed in double quotes” or “Expecting value”.

Can PasteKit remove trailing commas for me?

Yes. Click Fix it: it removes every trailing comma, along with other common problems, and shows the changes as a diff before you accept them.

Related