JSON CommenterOverviewJSON Commenter is a vscode extension that lets you create inline comments in a JSON file while keeping valid syntax. The text is edited inline and supports word wrap, padding, margins, etc. Features
Usage instructions.A single command (default: ctrl-alt-') anywhere in a json file opens a comment box at the nearest legal point. A setting determines if it opens above or below the click position. Clicking in that box opens an editor area where you enter the comment. Use normal text editing. The lines can be as long as you want and the words will wrap in the box later. Single returns are ignored but double returns (a blank line) will create a break to end the line. A click anywhere outside the editing area will finish the editing and the box appears in it's final form. You can reopen the editor at any time by just clicking inside the comment. Where can it be used?There are two general usage cases. One is commenting in a config file for an app you are using. Almost all apps just look for specific properties and ignore others. For example: it works great in package.json. In our limited testing we've found no apps that choke on the comments. If you find a problem app please post an issue in the repo. The other usage case is adding instructions to a config file for your own app. When loading the json you can ignore the extra object properties or use code provided below to strip them. How does it work?You might have noticed the property key values are empty. This violates the rule of no duplicate keys. But they aren't actually empty. There are zero-width invisible characters for id numbers. This not only guarantees no comment line duplicates but also guarantees no duplicates with other normal keys. The other tricky thing was finding legal points to insert comments. A full AST parser is used for that. Stripping comments when parsing.As mentioned above when you are using the json file as config for your own app you can just ignore the extra properties or use this code ...
Author: Mark HahnRepo: https://github.com/eridien/vscode-json-commenterOriginal Release: June 2025License: MIT |