JSON Errors / All languages
Trailing comma in JSON / Unexpected token }How to Fix: Trailing comma in JSON / Unexpected token }
JSON forbids a comma after the last element of an object or array. {"a": 1,} and [1, 2, 3,] both fail - JavaScript reports "Unexpected token }" or "]", Python reports "Expecting property name" or "Expecting value" at the position right after the comma.
Trailing commas are legal in modern JavaScript, Python, and most languages' literals - which is exactly why they leak into hand-edited JSON so often.
Common causes
1. Deleting the last item but keeping the comma
Removing the final entry of a list or object during editing leaves the previous line's comma dangling.
{
"debug": true,
"port": 8080,
}{
"debug": true,
"port": 8080
}2. Copying from JavaScript/TypeScript source
JS style guides encourage trailing commas in source code. Copying an object literal from code into a .json file carries them along.
3. Hand-generated JSON via string concatenation
Building JSON with loops and string concatenation appends a comma after every item, including the last. Use the language's serializer instead.
How to fix it
// JavaScript
JSON.stringify({ debug: true, port: 8080 }, null, 2);
# Python
json.dumps({"debug": True, "port": 8080}, indent=2)# regex that finds a comma followed only by whitespace and } or ]
grep -nE ',\s*[}\]]' config.jsonFrequently asked questions
Why does not JSON just allow trailing commas?
JSON's grammar was frozen for maximal interoperability in 2001, before trailing commas became a common language feature. Changing it now would break the guarantee that all JSON parsers accept the same documents. JSON5 and JSONC exist for humans who want the convenience.
VS Code accepts trailing commas in some .json files. Why?
Files like settings.json and tsconfig.json are parsed as JSONC (JSON with Comments), a Microsoft variant allowing comments and trailing commas. That leniency applies only to tools that opt in - standard JSON.parse and APIs still reject them.
Can a linter catch these before runtime?
Yes - jsonlint on the command line, ESLint for JSON files via plugins, and every CI JSON-schema validation step will flag trailing commas. Or paste the file into the validator on this page to locate the exact line.
Last updated:
Related JSON errors
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →