VS Code’s JSON editor is strict by default—it flags comments and trailing commas as errors, which is annoying when you’re editing config files that allow them (like tsconfig.json or launch.json). This guide shows you how to enable comments and trailing commas in VS Code’s JSON files, so you can write more flexible and readable configs without seeing red squiggles.
What You’ll Need
- VS Code (any recent version, 1.60 or later)
- A JSON file you want to edit (e.g.,
settings.json,launch.json, or a custom.jsonfile) - Basic familiarity with VS Code’s settings UI or
settings.json
Step-by-Step
- Open the Command Palette. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac).
- Search for “Preferences: Open Settings (JSON)”. Type “Open Settings (JSON)” and select it. This opens your user-level
settings.jsonfile. - Add the JSON validation override. In the settings file, add the following line inside the top-level JSON object (if it doesn’t exist, create it):
"json.validate.enable": false
This disables the built-in JSON validator for all JSON files, which is what flags comments and trailing commas as errors. - Save the file. Press Ctrl+S (or Cmd+S on Mac). The changes take effect immediately.
- Test it. Open any
.jsonfile, add a comment (e.g.,// this is a comment) or a trailing comma (e.g.,"key": "value",), and you should no longer see error squiggles. - Optional: Apply only to specific files. If you don’t want to disable validation globally, you can use the
files.associationssetting to treat certain files as JSON with comments. For example, add:"files.associations": { "*.jsonc": "jsonc" }
Then rename your file to.jsonc(or use thejsonclanguage mode) to get comment support without disabling validation for all JSON.
Common Mistakes
- Disabling validation globally without realizing it. This turns off error checking for all JSON files, which can hide real syntax errors. Use the
.jsoncapproach if you only need comments in a few files. - Forgetting to save the settings file. The change won’t apply until you save
settings.json. - Using the wrong setting name. The correct setting is
json.validate.enable, notjson.validateorjson.enableValidation. - Adding comments to files that other tools parse strictly. Even if VS Code allows comments, other tools (like build scripts or linters) may still reject them. Make sure your tooling supports comments or use
.jsoncfiles.
Tips
- Use the language mode selector. In the bottom-right corner of VS Code, click the language mode (e.g., “JSON”) and choose “JSON with Comments” to enable comments for that file only, without changing global settings.
- Prefer
.jsoncfor config files. Many tools (like VS Code’s ownsettings.json) already use JSONC, but for custom files, renaming to.jsoncmakes the intent clear. - Keep validation on for strict JSON. If you’re working with API payloads or data files, keep validation enabled to catch mistakes early.
- Use comments sparingly. Comments are great for explaining why a setting exists, but too many can clutter the file.
Troubleshooting
- Comments still show errors. If you disabled validation but still see red squiggles, check that the file is actually being treated as JSON (not JSONC). If it’s a
.jsonfile, the language mode might be “JSON” – switch to “JSON with Comments” via the language selector. - The setting doesn’t seem to apply. Make sure you edited the correct settings file. There are three levels: user, workspace, and folder. If you’re in a multi-root workspace, the setting might be overridden by a workspace setting. Check the gear icon in the Settings editor to see which level is active.
- Other extensions are still validating. Some extensions (like Prettier or ESLint) have their own JSON validation. Disable those extensions or configure them to ignore comments.
- VS Code crashes or behaves oddly after changing settings. Rarely, a malformed
settings.jsoncan cause issues. If that happens, open the file in a plain text editor and fix any syntax errors, or reset the setting to its default.
Frequently Asked Questions
Can I allow comments only in certain JSON files?
Yes. Use the files.associations setting to map specific file patterns to the jsonc language, or simply switch the language mode manually for each file.
Will disabling validation affect other features like formatting?
No. Formatting (like Prettier) works independently of validation. However, some formatting tools may still strip comments or trailing commas if they’re configured to do so.
Does this work with JSONC files?
Yes. JSONC (JSON with Comments) is natively supported by VS Code. Setting json.validate.enable to false also applies to .jsonc files, but they already allow comments by default.
Why does VS Code flag trailing commas as errors by default?
Because strict JSON (per the official specification) does not allow trailing commas. VS Code follows the spec by default to help you write standards-compliant JSON.
Is there a way to allow comments without disabling validation entirely?
Yes. Use the json.schemas setting to associate a JSON Schema that permits comments, or use the jsonc language mode, which has validation that ignores comments and trailing commas.
Does this setting affect all JSON files in my workspace?
If you set it in user settings, it affects all JSON files you open. If you set it in workspace settings, it affects only files in that workspace.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Delete Picture Kik? How to Remove Photos
- What Happens to X Replies, DMs, and Followers After Deletion?
- Data Breaches That Shook the World
- Disable Google Assistant: Turn It Off on Android & Home
- Resin vs FDM Printers for Miniatures: Detail, Durability, Cost
- Are Networked Implants Safe? What If One Fails?