In modern JavaScript, adding a trailing comma to the last key in an object literal is standard practice. However, putting a trailing comma into a JSON file or API response causes an immediate SyntaxError: Unexpected token } in JSON.
In formal BNF grammar, a JSON object is defined as: object = begin-object [ member *( value-separator member ) ] end-object. Notice the value-separator (comma) must always be followed by a valid member. It cannot precede end-object directly.
[
"apple",
"banana",
"cherry",
][
"apple",
"banana",
"cherry"
]Check where the dangling comma breaks array iteration.
{
"status": 200,
"records": [1, 2, 3,],
}ECMAScript 5 allowed trailing commas in object literals, and ES2017 extended this to function parameter lists. This was done intentionally to minimize multi-line git diff noise when adding new items to the bottom of lists. Because JSON was standardized earlier in RFC 4627 (2006) to be multi-language compatible across C++, Python, and Java, it never adopted this JS-specific leniency.