VS Code has been letting you write invalid JSON for years, and it’s completely intentional
For years developers have trusted Visual Studio Code to be the go‑to editor for JSON files, assuming the editor would enforce strict JSON syntax. In reality, VS Code has been silently allowing a range of “invalid” constructs, and this isn’t a bug—it’s a deliberate design choice rooted in how Microsoft envisions its configuration files.
What Happened
When users opened settings, launch configurations, or workspace files in VS Code, they often typed comments, trailing commas, or even unquoted keys, all of which violate the official JSON specification. Rather than flagging these issues, the editor quietly accepted them, rendering the files without complaint. This behavior puzzled many, especially when the same files failed validation in other tools.
Investigation revealed that the VS Code team had intentionally disabled strict JSON validation for certain file types. The editor’s built‑in language service treats these configuration files as a “relaxed JSON” format, allowing syntactic shortcuts that make manual editing faster and more forgiving for developers who aren’t JSON experts.
Key Details
The relaxed parsing is powered by a custom JSON schema that marks comments (// and /* */) and trailing commas as permissible. Additionally, the language server tolerates duplicate keys and unquoted property names, converting them to the canonical form behind the scenes. This transformation happens only inside the editor; the actual file on disk retains the user‑written text.
Because the feature is baked into the core extension for JSON, it applies to any file that matches the *.jsonc* pattern or is explicitly associated with a VS Code configuration schema. The extension also provides IntelliSense and auto‑completion based on the relaxed syntax, which would be impossible if the editor enforced strict JSON at every keystroke.
Background
Microsoft’s vision for VS Code’s configuration ecosystem dates back to the early days of the editor, when the team wanted to lower the barrier for non‑technical users. By allowing comments and other conveniences, developers could annotate settings, explain why a particular launch configuration existed, or temporarily disable a block of code without breaking the file.
This philosophy mirrors other Microsoft products, such as Azure Resource Manager templates, which use a “JSON with comments” (JSONC) format. The decision to keep this approach consistent across VS Code meant that the editor would never enforce pure JSON, even though the underlying file extension remained *.json*.
Why It Matters
The intentional laxness has practical benefits: teams can maintain readable, well‑documented config files, and newcomers can edit settings without learning the full JSON spec. However, it also introduces a hidden divergence between what VS Code accepts and what external tools, CI pipelines, or APIs expect, potentially leading to runtime errors.
Moreover, the discrepancy can cause confusion in collaborative environments. A teammate using a different editor may see validation errors, while the VS Code user sees none. This mismatch forces teams to adopt additional linting steps or rely on VS Code‑specific extensions to ensure compatibility across the development stack.
What Happens Next
Microsoft has confirmed that the relaxed JSON mode will remain, but the company is improving documentation and adding explicit warnings when files contain non‑standard constructs. Future releases will include a toggle in the settings UI, allowing users to switch between strict and relaxed validation, giving teams the flexibility to enforce standards when needed.
Community extensions are also stepping up, offering linters that flag JSONC‑specific syntax before code is committed. By integrating these tools into the typical VS Code workflow, developers can enjoy the convenience of comments and trailing commas while still catching incompatibilities early in the development cycle.
In the end, VS Code’s decision to permit “invalid” JSON reflects a broader trade‑off between developer ergonomics and strict standards compliance. Understanding that VS Code treats many of its configuration files as a superset of JSON helps teams make informed choices about tooling, documentation, and code review practices, ensuring that the convenience of relaxed syntax doesn’t become a hidden source of bugs.
📖 See Also
📚 Sources & Attribution
- ✓ MakeUseOf