JSONC to JSON (Strip Comments)
VS Code’s settings.json, tsconfig.json, and many other config files use JSONC — JSON with Comments. Most JSON parsers reject the // and /* */ comment syntax. This tool strips comments while leaving every other character intact, including trailing commas (toggleable). Output parses cleanly with any strict JSON parser.
How to use the JSONC to JSON (Strip Comments)
Paste your JSONC file. The tool walks character-by-character, removing // line comments and /* */ block comments while respecting string boundaries (so // inside a quoted string is preserved). Trailing commas (commas before ] or }) are technically not part of JSONC but most editors tolerate them — toggle the option to clean those up too if your target parser is strict.
If pretty-print is on, the result is re-formatted with two-space indent for readability. Turn it off if you want to preserve the original layout (minus comments).
About JSONC to JSON (Strip Comments)
JSONC — “JSON with Comments” — is a small extension of JSON that allows // line comments and /* */ block comments. There’s no formal RFC, but it’s the de-facto format for VS Code’s configuration files: settings.json, keybindings.json, tsconfig.json, tasks.json, launch.json. Microsoft’s tooling parses comments transparently, but if you need to pipe that config through any other JSON-aware tool — jq, a Python script, an HTTP API — you’ll get parse errors.
The fix is simple: strip the comments. The catch is doing it without false positives. Naive regex replacement breaks on JSON strings that contain // or /* as literal characters (a URL field, a regex pattern, a code snippet). This tool walks the document with a tiny state machine that tracks whether the current character is inside a string, so comment-stripping is always correct.
Common use cases
- Piping VS Code settings to jq — strip comments first so jq can parse the file.
- Sending tsconfig.json to a CI tool that uses a strict JSON parser.
- Migrating from JSONC to JSON when consolidating config formats.
- Auditing dotfiles repos — produce clean JSON snapshots for diffing across machines.
Frequently asked questions
Does it preserve string contents?
"\"https://example.com/path\"" stays intact.