Why VS Code says comments are not permitted in JSON
VS Code shows Comments are not permitted in JSON. (521) when a file open in JSON mode contains // or /* */, because standard JSON has no comments. Files that VS Code opens in JSON with Comments mode never get it. Out of the box that covers:
settings.json,launch.json,tasks.json,keybindings.json,extensions.json,devcontainer.jsontsconfig.json,jsconfig.jsonand variants such astsconfig.app.json.eslintrc.json,.babelrc,babel.config.jsonand any.jsoncfile
Every other .json file is strict. You see 521 when:
- A config that accepts comments has a plain
.jsonname. ASP.NET Core’sappsettings.jsonis one: its loader skips comments. - Someone commented a file whose reader rejects them. On a commented
package.json, npm stops withEJSONPARSEandpackage.json must be actual JSON, not just JavaScript. - JSONC or JSON5 text was pasted into a
.jsonfile.
How to fix it
Switch the file to JSON with Comments
Click JSON in the Status Bar, or run Change Language Mode (Ctrl + K M, Cmd + K M on macOS), and pick JSON with Comments. To make it permanent for everyone on the project, map the files in .vscode/settings.json:
{
"files.associations": {
"appsettings*.json": "jsonc",
"**/config/*.json": "jsonc"
}
}
A pattern without a slash matches the file name; with a slash, it matches the full path, hence the **/.
Check the reader first
The language mode only changes the editor. TypeScript reads comments in tsconfig.json and ASP.NET Core skips them in appsettings.json, but npm, JSON.parse, Python’s json module and most APIs reject them. For package.json, keep notes in a key instead: "//": "pinned until the v5 migration". npm treats it as ordinary data.
Remove the comments
Paste the file into JSON Repair. Repair deletes // and /* */ comments and keeps the data. For the sample above it returns:
{
"port": 5173,
"proxy": "http://localhost:8080"
}
Then confirm nothing else is wrong in the JSON validator.
Turn validation off
"json.validate.enable": false in the workspace settings silences 521, along with every real syntax error in every JSON file of the project.
Same error elsewhere
- JetBrains IDEs: the comment message comes from the inspection behind JSON standard does not allow such tokens, which lists the IDE’s fixes.
- Chrome and Node.js: a comment inside an object gives Expected property name or ‘}’ in JSON.
- Safari and Bun:
JSON Parse error: Unrecognized token '/'.
More on JSONC and JSON5: can JSON have comments. Other parser messages: common JSON errors.