Skip to content

Editors, CLI and databases

Comments are not permitted in JSON. (521)

VS Code is validating the file as standard JSON, which has no comment syntax, so every // or /* */ comment is an error.

Updated · 2 min read

console
VS CodeComments are not permitted in JSON. (521)
IntelliJ IDEA, PyCharm, WebStormJSON standard does not allow comments.
Chrome, Edge, Node.js (JSON.parse)SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
Python jsonjson.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)

Find it in your JSON

Paste the text that failed. The checker points at the exact spot, and Repair fixes most syntax mistakes.

Input · JSON

Invalid JSON

Line 2, column 3

Comments are not allowed in JSON.

1{2  // Local development only   ^3  "port": 5173,

Fix: Delete the comment, or use Repair to strip comments automatically.

Why this happens
Invalid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

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.json
  • tsconfig.json, jsconfig.json and variants such as tsconfig.app.json
  • .eslintrc.json, .babelrc, babel.config.json and any .jsonc file

Every other .json file is strict. You see 521 when:

  1. A config that accepts comments has a plain .json name. ASP.NET Core’s appsettings.json is one: its loader skips comments.
  2. Someone commented a file whose reader rejects them. On a commented package.json, npm stops with EJSONPARSE and package.json must be actual JSON, not just JavaScript.
  3. JSONC or JSON5 text was pasted into a .json file.

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

More on JSONC and JSON5: can JSON have comments. Other parser messages: common JSON errors.

Questions

Does JSON with Comments allow trailing commas?

Yes, with a warning: Trailing comma (519). The program that reads the file has to accept them as well.

Is JSONC the same as JSON5?

No. JSONC is JSON plus comments. JSON5 also allows single quotes, unquoted keys, hex numbers and more. VS Code has no built-in JSON5 mode; an extension adds one.

Related errors

All common JSON errors

Esc