Fix JSON trailing comma error in VS Code settings.json starts with a surprise: in settings.json itself, the trailing comma often causes no error at all. Copy that same text into an app config file, a data file, or a request body, and a strict parser rejects it on the spot. The file did not change. The rules did.
The reason is the language mode in the status bar at the bottom right of VS Code. VS Code opens its own config files in JSON with Comments mode, called JSONC. That mode allows comments and tolerates trailing commas, flagging them as warnings in a plain .jsonc file and treating its own config files even more leniently. Strict JSON, the format defined by RFC 8259, allows neither comments nor a comma after the last item in an object or array. So a settings.json file can look clean while holding text that no strict parser will accept.
Here is the shape of the mistake. This passes in settings.json:
{
"editor.fontSize": 14,
"workbench.colorTheme": "Default Dark+",
}
That last comma after the theme line is the whole problem. Remove it and the text is strict JSON:
{
"editor.fontSize": 14,
"workbench.colorTheme": "Default Dark+"
}
Nothing else changed. One character decided whether the file parses.
Why settings.json tolerates a trailing comma and strict JSON does not
JSONC exists because config files are written by humans. People comment out a setting to test it, reorder lines, and leave a comma behind. The JSONC parser, node-jsonc-parser in VS Code, was built to absorb that kind of editing. Strict JSON was built for data exchange between programs, where every consumer must read the same text the same way. A trailing comma adds nothing to the data, so the spec left it out. Two different jobs, two different grammars, one file extension.
That split explains the most confusing symptom: the same snippet errors in one tab and not in another. A file named app-config.json opens in strict JSON mode and the comma draws a red squiggle. The same text saved as settings.json or as a .jsonc file draws a warning at most. The status bar tells you which mode you are in. Click it and you can switch a file between JSON and JSON with Comments, or map a filename pattern to jsonc through files.associations. If you are hunting an error, check the mode before you trust the absence of squiggles.
The copy and paste trap that ships the error
Most trailing comma errors I see in real projects arrive by copy and paste. Someone copies a block out of settings.json into a test fixture, a seed file, or a CI config, and the strict parser in that pipeline fails with an error like Unexpected token } in JSON. The message points at the closing brace, not at the comma. That misdirection costs time, because the brace looks innocent and the eye skips the comma on the line above it.
There is a second trap in the other direction. A developer pastes strict JSON into settings.json, adds a comment to explain a setting, and later copies the whole block back out with the comment still in it. Now the file fails twice over: a comment and possibly a trailing comma, both illegal in strict JSON. The fix in both directions is the same habit. Before text leaves your editor, run it through a strict parser. That one check catches comments, trailing commas, single quotes, and unquoted keys in a single pass, and it costs nothing.
The fastest way to find every trailing comma in a file is a regex search for a comma followed by a closing brace or bracket: ,\s*[}\]]. It finds commas at the end of objects, arrays, and nested structures alike. In a large file, that beats scanning by eye, because the error hides exactly where the eye stops looking, right before a closing bracket. Extensions like Fix All JSON can also repair these on save for json and jsonc files, which suits people who edit config constantly. I still prefer the strict parse as the final check, because an extension fixes what it recognizes and a parser verifies everything.
So the rule I use: JSONC inside the editor, strict JSON everywhere else. Write comments and trailing commas in settings.json if that helps you work. Strip them the moment the text becomes data. And when a parser complains about a closing brace, look at the line above it first. The comma is usually sitting right there, quiet and guilty.
Paste the text into the JSON Repair Tool to find the exact position of the error, fix it, and verify the result parses as strict JSON before you ship it.
Frequently asked questions
Why does settings.json allow trailing commas when JSON does not?
Because VS Code opens its own config files in JSONC mode, which tolerates comments and trailing commas. Strict JSON under RFC 8259 allows neither, so a parser like JSON.parse rejects the same text.
How do I check which mode a file is in?
Look at the status bar at the bottom right of VS Code. It shows JSON or JSON with Comments. Click it to switch modes, or use files.associations to map a filename pattern to jsonc.
What error does a trailing comma produce in strict JSON?
Usually an Unexpected token error pointing at the closing brace or bracket after the comma. Look at the line above the reported position: the stray comma is normally there.
Does Prettier fix trailing commas in JSON?
Prettier can format JSON and apply a trailing comma setting, but the reliable check is a strict parse afterward. Formatting and validating are different jobs, and the parse is the one that proves the file is valid.
Can I keep comments in settings.json?
Yes, in settings.json itself. Comments are part of JSONC. Remove them, along with any trailing commas, before the text is used as strict JSON data anywhere else.
One practical note a week: subscribe on Substack.