JSON troubleshooting

JSON trailing comma errors in objects and arrays

Remove trailing commas that strict JSON parsers reject. See version-specific JavaScript, Python and .NET messages and generate valid JSON with serializers.

What the error means

A comma separates two members of an object or two elements of an array. A comma directly before the closing brace or bracket leaves the next member or element missing. Standard JSON disallows it even though JavaScript and some configuration formats accept it. Different parsers can report a missing property name or an unexpected closing bracket.

Exact messages by runtime

Messages depend on the input and runtime version. Node and Python rows were reproduced locally. Other rows cite official documentation or source. Rows marked as fragments or templates preserve the source wording and are not complete exception transcripts. Browsers and libraries may append location details.

RuntimeMessageInput and evidence
JavaScript / V8, arraySyntaxError: Unexpected token ']', "[1,]" is not valid JSONJSON.parse("[1,]")
Reproduced in Node.js 24.21.0
JavaScript / V8, objectSyntaxError: Expected double-quoted property name in JSON at position 8 (line 1 column 9)JSON.parse('{"id":1,}')
Reproduced in Node.js 24.21.0
Python 3.13+, arrayjson.decoder.JSONDecodeError: Illegal trailing comma before end of array: line 1 column 3 (char 2)json.loads("[1,]")
Reproduced in Python 3.14.4; explicit diagnostic added in official CPython 3.13.0 source
Python 3.13+, objectjson.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 1 column 8 (char 7)json.loads('{"id":1,}')
Reproduced in Python 3.14.4; explicit diagnostic added in official CPython 3.13.0 source
Python 3.12 and earlier, objectExpecting property name enclosed in double quotesTrailing comma before }
Official CPython 3.12.0 diagnostic text; location depends on input
Python 3.12 and earlier, arrayExpecting valueTrailing comma before ]
Official CPython 3.12.0 diagnostic text; location depends on input
FirefoxSyntaxError: JSON.parse: unexpected characterTrailing-comma examples in MDN
MDN example wording, location suffix omitted
Safari / JavaScriptCoreJSON Parse error: Unexpected comma at the end of array expressionTrailing comma in an array
Official WebKit parser message and LiteralParser.h prefix
C# / System.Text.JsonThe JSON array contains a trailing comma at the end which is not supported in this mode. Change the reader options.Array with a trailing comma, default strict mode
Official .NET 10 resource string, path and location suffix omitted

Causes you can reproduce

A JavaScript array was pasted into a JSON file

The final comma in a JavaScript array literal can be convenient for editing, but it must be absent in JSON text.

JAVASCRIPT
JSON.parse('[1,2,]');

An object member was deleted without removing its comma

After removing the last property, inspect the property now at the end of the object.

PYTHON
import json
json.loads('{"id":1,}')

A template adds a comma after every item

A loop that appends a comma to each value leaves one extra comma at the end. Build the array and serialize it instead.

JAVASCRIPT
const text = '[' + [1, 2].map(n => n + ',').join('') + ']';
JSON.parse(text);

How to fix it

  1. Find the closing } or ] near the reported position. Check whether its previous non-whitespace character is a comma.
  2. Remove that separator while leaving commas between members or elements intact.
  3. Replace manual JSON templates with a serializer. Confirm whether the file is standard JSON or a deliberately permissive configuration format.
  4. Validate the whole document again. Do not remove comma characters globally because commas can occur inside strings.

Generate an array with JSON.stringify

The serializer inserts separators between values and never appends a trailing comma.

JAVASCRIPT
const text = JSON.stringify([1, 2]);
const values = JSON.parse(text);
// text is [1,2]

Generate an object with json.dumps

Use the JSON module instead of a loop that writes individual members and separators.

PYTHON
import json
text = json.dumps({"id": 1})
data = json.loads(text)

Find the exact position with Tool Kumar

  1. Copy the exact input text, including its original whitespace. For HTTP failures, copy the raw response body.
  2. Open the Tool Kumar JSON validator and paste the text. The document stays in your browser.
  3. Read the line and column in the error or fixable-issue banner. For an invalid document, select Go to error to move the caret to that location.
  4. Inspect the preceding token as well as the marked character. A parser marks where it discovered the problem; the missing quote, separator or value can start earlier.

Python character offsets are zero-based, while its displayed lines and columns are one-based. V8 string positions count UTF-16 code units; Go offsets count bytes read. Unicode text can make these offsets differ. Use the original text and its line/column context rather than copying an offset between runtimes.

Tool Kumar can classify some input as fixable loose JSON. Review a proposed change before using the repair action, then validate the result against your API contract. For empty input, inspect the producer or response because there is no character to select.

Frequently asked questions

Are trailing commas allowed in JSON?

No. RFC 8259 and ECMA-404 allow commas between members or elements, with no comma after the final member or element.

Why does my editor accept a trailing comma?

The editor may use a permissive mode or treat the file as JSONC or JavaScript. Acceptance by an editor does not make the text valid standard JSON.

Should I enable AllowTrailingCommas in .NET?

Use it only if your input contract deliberately permits that extension. For JSON exchanged across runtimes, remove the comma so strict parsers can read the document.

Why does Python report different trailing-comma errors?

Python 3.13 and later name an illegal trailing comma explicitly. Python 3.12 and earlier report a property-name error for objects or Expecting value for arrays. Each identifies the comma before the closing delimiter.

Standards and diagnostic sources

RFC 8259 and ECMA-404 define JSON syntax. Diagnostic wording belongs to the parser. The table links each cited message to its source.