Trailing comma in JSON: “Expected double-quoted property name”
Updated
A comma is a promise of one more item. The bracket closes, the promise is broken, and the parser stops there. JSON allows no comma after the last member of an object or the last element of an array, so {"a": 1,} and [1, 2,] are both invalid.
The error and the fix
The usual shape: a list or an object edited by hand, where the last line kept its comma after a line below it was deleted or moved.
{
"id": "op-0042",
"tags": ["quiet", "fast",],
"mercy": false,
}Two commas to delete: after "fast" and after false. Nothing else changes:
{
"id": "op-0042",
"tags": ["quiet", "fast"],
"mercy": false
}A parser reports the first problem only. Fix the comma inside the array, run the check again, and the second one shows up on the next pass.
Why JSON forbids a trailing comma
RFC 8259, section 4, defines a comma as a separator, not a terminator: “A single comma separates a value from a following name.” The grammar says the same for both containers: object = begin-object [ member *( value-separator member ) ] end-object and array = begin-array [ value *( value-separator value ) ] end-array. A separator needs something on both sides. After the last item there is nothing, so the comma has no place in the grammar.
JavaScript, Python, Go and Rust all accept a trailing comma in their own literals (Go even requires one in multi-line literals), which is exactly why it ends up in JSON. JSON froze its grammar to stay the same everywhere; JSONC and JSON5 relaxed it, and they are different formats.
Trailing comma error messages by parser
The same two inputs, {"a": 1,} and [1, 2,], in each parser. Most of them complain about what comes after the comma, the closing bracket, because that is where they gave up waiting for another item.
| Parser | Object: {"a": 1,} | Array: [1, 2,] |
|---|---|---|
| Chrome, Edge, Node.js (V8) | Expected double-quoted property name in JSON at position 8 (line 1 column 9) | Unexpected token ']', "[1, 2,]" is not valid JSON |
| Node.js 18, older Chrome (V8 10.2) | Unexpected token } in JSON at position 8 | Unexpected token ] in JSON at position 6 |
| Firefox | JSON.parse: expected double-quoted property name at line 1 column 9 of the JSON data | JSON.parse: unexpected character at line 1 column 7 of the JSON data |
| Safari | JSON Parse error: Property name must be a string literal | JSON Parse error: Unexpected comma at the end of array expression |
| Python 3.13 and newer | Illegal trailing comma before end of object: line 1 column 8 (char 7) | Illegal trailing comma before end of array: line 1 column 6 (char 5) |
| Python 3.12 and older | Expecting property name enclosed in double quotes: line 1 column 9 (char 8) | Expecting value: line 1 column 7 (char 6) |
| Go (encoding/json) | invalid character '}' looking for beginning of object key string | invalid character ']' looking for beginning of value |
| Java (Jackson 2) | Unexpected character ('}' (code 125)): was expecting double-quote to start field name | Unexpected character (']' (code 93)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') |
| C# (System.Text.Json) | The JSON object contains a trailing comma at the end which is not supported in this mode. Change the reader options. | The JSON array contains a trailing comma at the end which is not supported in this mode. Change the reader options. |
| C# (Newtonsoft.Json) | No error: the comma is accepted | No error: the comma is accepted |
| PHP (json_decode) | Syntax error, json_last_error() 4 | Syntax error, json_last_error() 4 |
| Rust (serde_json) | trailing comma at line 1 column 9 | trailing comma at line 1 column 7 |
| jq | jq: parse error: Expected another key-value pair at line 1, column 9 | jq: parse error: Expected another array element at line 1, column 7 |
| Visual Studio Code | Trailing comma, problem 519, underlined at the comma | Trailing comma, problem 519 |
Only Python 3.13+ and Visual Studio Code point at the comma itself; everyone else points one token later. Jackson 3 says “property name” instead of “field name”. Checked by running: Node.js 18, 24 and 25.1 (V8 14.1), Safari 27 (JavaScriptCore, macOS 27), Python 3.9, 3.12, 3.13 and 3.14, Go 1.25–1.27, Jackson 2.22 and 3.2, System.Text.Json and Newtonsoft.Json 13.0.4 on runtime 10.0, PHP 8.3 and 8.5, serde_json 1.0, jq 1.7 and 1.8. Firefox and Visual Studio Code: from their source code; Firefox’s messages are also listed on Mozilla’s reference pages.
Where trailing commas come from
- Deleting the last line. The line above it keeps its comma and becomes the new last line.
- Templates. A loop prints
{{ item }},for every item, including the last one. Most template engines have a “last iteration” check or a join filter for this. - Code literals pasted as data. A JavaScript object or a Python dict with a trailing comma is valid code and invalid JSON.
- Merges. Two branches each add a line at the end of a list; the merged file has a comma too many or one too few (that one is a missing comma).
How to fix a trailing comma in code
Data your program writes should never contain one: every standard serializer separates items and never leaves a comma at the end. The snippets below show the error from the reading side and, where it exists, the switch that accepts trailing commas in files written by people (for System.Text.Json: allow some kinds of invalid JSON).
JavaScript
// Build JSON with JSON.stringify, not with string joins: no trailing commas.
const body = JSON.stringify({ tags: ["quiet", "fast"] });
console.log(body); // {"tags":["quiet","fast"]}
try {
JSON.parse('{"a": 1,}');
} catch (e) {
console.log(e.message); // Expected double-quoted property name in JSON at position 8 (line 1 column 9)
}Python
import json
try:
json.loads('{"a": 1,}')
except json.JSONDecodeError as e:
# Python 3.13+: "Illegal trailing comma before end of object", e.pos is the comma
print(e.msg, e.lineno, e.colno)
print(json.dumps({"tags": ["quiet", "fast"]})) # {"tags": ["quiet", "fast"]}Go
package main
import (
"encoding/json"
"errors"
"fmt"
)
func main() {
var v any
err := json.Unmarshal([]byte(`{"a": 1,}`), &v)
var se *json.SyntaxError
if errors.As(err, &se) {
// Offset is the number of bytes read: 9, just past the closing brace.
fmt.Println(se.Offset, err)
}
}Java (Jackson)
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readTree("{\"a\": 1,}");
} catch (JsonProcessingException e) {
// 1:9, the closing brace right after the comma
System.out.println(e.getLocation().getLineNr() + ":" + e.getLocation().getColumnNr());
}Jackson accepts trailing commas only with JsonReadFeature.ALLOW_TRAILING_COMMA enabled (see its read features); leave it off for data that comes from other programs.
C#
using System.Text.Json;
// For config files written by people: accept the comma explicitly.
var options = new JsonDocumentOptions { AllowTrailingCommas = true };
using var doc = JsonDocument.Parse("{\"a\": 1,}", options);
Console.WriteLine(doc.RootElement.GetProperty("a")); // 1PHP
$json = '{"a": 1,}';
var_dump(json_validate($json)); // bool(false), PHP 8.3+
json_decode($json);
echo json_last_error_msg(), "\n"; // Syntax error
echo json_encode(['tags' => ['quiet', 'fast']]); // {"tags":["quiet","fast"]}How to keep trailing commas out
- Generate JSON with a serializer:
JSON.stringify,json.dumps,json.Marshal, Jackson,JsonSerializer,json_encode. - In templates, join the items instead of appending a comma to each one.
- Validate files written by hand before they ship: a pre-commit hook, a CI step or the JSON validator.
- If people really need trailing commas in a config, pick a format that has them (JSONC, JSON5, YAML) and parse it with a parser for that format, not with a JSON parser in lenient mode.
Try it in the validator
Open a sample with a trailing comma in the JSON validator. It reports the code trailing_comma with the line and column of the comma itself, not of the bracket after it, and Show me puts the cursor on it.
Related: missing comma, comments in JSON, unclosed bracket, and the full list of JSON errors.
Trailing comma FAQ
Is a trailing comma allowed in JSON?
No. RFC 8259 allows a comma only between two values or two members. JSONC and JSON5 allow it, but they are separate formats, and a strict JSON parser rejects them.
Why does Chrome say “Expected double-quoted property name” when there is no property?
After a comma inside an object, V8 expects the next key, and a key must be a double-quoted string. It finds } instead and reports what it expected. The cause is the comma before it.
Why does the error point at the bracket and not at the comma?
Most parsers only know the comma was wrong when they see what follows it. Python 3.13+, Visual Studio Code and this site’s validator point at the comma itself.
Can I just remove trailing commas with a regular expression?
Only if no string in the document contains a comma followed by a bracket, and that is hard to promise. Fix the source that writes them, or parse the file with a JSON5 or JSONC parser.