How to Use JSON With Comments for Configs

Comments can be added to JSON using a VS Code folder along with a files.associations top-level object. Here’s how to do it. 

Written by Chris Cook
Published on Jun. 10, 2025
Developers reviewing code and writing comments
Image: Shutterstock / Built In
Brand Studio Logo
Summary: JSON doesn’t natively support comments, but VS Code lets you treat specific files as JSON with comments using files.associations in .vscode/settings.json. This enables tools like Turbo to show comment support without syntax errors while preserving config readability.

Most of the tools we use daily in the Node.js ecosystem utilize config files that support various formats such as .js/cjs/mjs, .yaml/toml, or .json. I usually prefer to work with simple text formats like JSON over JavaScript because it spares me the hassle of navigating the ESM versus CJS battle for the correct file extension and export specifier. Even better, if the config publishes a JSON schema, then you get type safety without having to rely on JSDoc or TypeScript types.

4 Steps to Allow Comments in JSON

  1. Create a .vscode folder in your workspace root.
  2. Create a settings.json file in .vscode folder.
  3. Create a "files.associations"top-level object
  4. Create a property for each file name that you want to treat as JSON comments.

The biggest downside to using JSON for config files is, in my opinion, its lack of support for comments. I want to explain why I enabled a certain feature or disabled a certain rule.

More on JavaScriptHow to Split a String in JavaScript

 

Why Doesn’t JSON Support Comments?

JSON was initially designed to be a simple and compact data exchange format, inspired directly by JavaScript’s object literal syntax. Comments were deliberately left out by the creator Douglas Crockford because he believed adding comments would affect the interoperability. This decision remains a controversy to this day and resulted in a new format being created: JSON with Comments (.jsonc).

A tutorial on how to add comments to a JSON file. | Video: WebStylePress

More on Software EngineeringHow to Check for Log Errors With Jest

 

How to Use JSON With Comments for Configs

I know most tools still accept comments in JSON files because they don’t use the native JSON.parse function, which errors on comments, but instead use custom packages like JSON5 that support comments.

My new go-to linter, Biome.js, solves this by accepting a biome.jsonc (JSON with comments) as a config file. However, other build tools like Turbo only accept a plain turbo.json file, even though they allow for comments embedded in the JSON. When you open this file in VS Code, you will encounter numerous errors because of the comments.

Comments not permitted screenshot of code
Comments aren’t permitted in JSON error screen. | Screenshot: Chris Cook

VS Code opens this file based on its file extension in JSON language mode (see the language indicator in the bottom bar). Interestingly, if you open  tsconfig.json, you will notice that VS Code interprets this file as JSON with comments even if it doesn’t contain any comments.

JSON with comments enabled.
JSON with comments enabled code file. | Screenshot: Chris Cook

VS Code allows you to associate a file name with a certain language. These file associations are defined in the .vscode/settings.json file:

// .vscode/settings.json
{
  "files.associations": {
    "turbo.json": "jsonc"
  }
}

Now, opening the turbo.json file again will automatically use the right language (JSON with comments). However, keep in mind that you should verify if your tool actually supports JSON with comments. For example, Node.js doesn’t support comments in package.json, and doing so will break your package and potentially all dependent packages.

Frequently Asked Questions

  1. Create a .vscode folder in your workspace root.
  2. Create a settings.json file in .vscode folder.
  3. Create a "files.associations"top-level object.
  4. Create a property for each file name that you want to treat as JSON comments.

JSON comments were deliberately left out by the creator Douglas Crockford because he believed comments affected interoperability. However, the format JSON with comments (.jsonc) was created to resolve this issue.  

Explore Job Matches.