October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Why VS Code Lets You Write “Invalid” JSON: JSONC Explained

VS Code accepts comments and trailing commas in JSON with Comments (JSONC) mode. Here’s how that differs from strict JSON and schema validation.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

VS Code accepts comments and trailing commas when a file is in JSON with Comments mode (JSONC), not because ordinary JSON allows them. Its standard JSON mode follows JSON syntax; the active language mode determines what the editor accepts. Whether the file will work elsewhere depends on what consumes it.

Why does VS Code allow comments in JSON files?

VS Code has separate language modes for JSON and JSON with Comments. JSONC is used for VS Code configuration files such as settings.json, tasks.json and launch.json. In that mode, the editor accepts JavaScript-style line comments (//), block comments (/* ... */) and trailing commas. These extensions are not part of standard JSON.

As an Amazon Associate I earn from qualifying purchases.

The filename alone does not tell you which syntax is active. Check the language-mode indicator in VS Code’s status bar. Select it to change the mode, or configure an extension-to-mode association. Microsoft documents the behavior, but its documentation does not establish when JSONC support began or explain the original design rationale; “for years” and “completely intentional” should not be read as sourced historical claims. Microsoft’s JSON documentation describes the modes and their behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Comments are accepted; trailing commas are warned about

JSONC accepts both line and block comments. It also accepts trailing commas, but Microsoft warns against them and says the editor displays a warning. A file that VS Code can edit in JSONC mode may still fail when another tool reads it as strict JSON.

What does JSONC look like?

In JSONC mode, VS Code accepts examples like these:

{
  // A line comment
  "editor.tabSize": 2,
  "files.trimTrailingWhitespace": true,
}

The comment and the comma after the last property are JSONC conveniences. Remove them if the file must be valid strict JSON. The trailing-comma warning is a useful signal, but the key compatibility question is whether the program that reads the file supports JSONC.

Does schema validation make the file strict JSON?

No. Syntax mode and schema validation answer different questions. The selected language mode determines which syntax VS Code accepts. An associated JSON Schema can separately check whether the document has the expected structure and values, and VS Code can show diagnostics for schema violations. Passing schema checks does not make JSONC syntax acceptable to a strict JSON parser.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

VS Code supports JSON Schema drafts 4 through 7, with limited support for drafts 2019-09 and 2020-12. Validation can be controlled with json.validate.enable. Microsoft documents schema support and validation in its JSON language guide.

How should you associate a schema?

You can associate a schema by adding a $schema property to the document, using the json.schemas setting, or relying on a schema mapping contributed by an extension. The inline property is explicit, but it becomes part of the data. A consumer may reject that extra key if its expected format does not allow it.

When adding a property would change data that another program expects, use a settings-based mapping instead. VS Code documents json.schemas as an alternative to placing $schema in the document. See Microsoft’s guidance on JSON Schema mapping.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which mode should you use?

  • Use JSONC when the file is intended for a VS Code feature or another consumer that supports comments and the other JSONC syntax you use.
  • Use strict JSON when a downstream parser expects standard JSON, or when you cannot confirm that it accepts JSONC. Avoid comments and trailing commas in that file.
  • Check both syntax and shape when the file must meet a particular data format: select the appropriate language mode and associate a schema for structural and value diagnostics.

For project configuration, VS Code distinguishes user settings from workspace settings. Workspace settings live in the project’s .vscode directory and can be shared with the project; user settings apply to an individual VS Code setup. The settings editor provides IntelliSense for settings.json, and VS Code highlights incorrect setting names and JSON formatting errors. Microsoft’s settings guide explains the scopes.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to check when a file works in VS Code but fails elsewhere

  1. Check the language mode: select the status-bar mode indicator and confirm whether the file is in JSON or JSON with Comments.
  2. Inspect the syntax: remove comments and trailing commas if the consumer requires strict JSON.
  3. Identify the consumer’s requirements: editor acceptance does not prove that a separate parser or application accepts the same syntax.
  4. Separate schema errors from syntax errors: use an associated schema to check expected structure and values, but do not treat schema validation as proof of strict JSON compatibility.
  5. Review schema placement: if an inline $schema key could be rejected as unexpected data, associate the schema through json.schemas instead.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.