JSONC to JSON — strip comments and trailing commas from config files

Paste JSON with comments, such as a tsconfig.json or VS Code settings file, and get strict JSON with every comment and trailing comma removed, ready for any JSON parser.

Live demo · real result from this tool
Indent

JSON

{  "editor.tabSize": 2,  "files.exclude": {    "**/.git": true,    "**/node_modules": true  },  "url": "https://toolsrift.com//not-a-comment"}

Processed on your device — nothing is uploaded.

How to use the JSONC to JSON converter

  1. Paste your file into the Input box. The sample is a VS Code settings file with both comment styles and trailing commas.
  2. Choose the Indent: 2 spaces, 4 spaces, Tab or Minified.
  3. Copy the JSON or download it as settings.json.
  4. If something else is wrong, the error names the line and column.

What it does and when to use it

Comments make config files easier to maintain, but many programs only read strict JSON: jq, Python’s json module, most API clients, CI scripts and online validators. When you need to feed a tsconfig.json, an .eslintrc.json or a VS Code settings.json into one of those, this tool removes the parts they reject and leaves the data untouched. It also serves as a cleaner when you paste a commented example from documentation into a project that forbids comments.

After converting, you can check the structure with the JSON validator or turn it into other formats with JSON to YAML or JSON to TOML.

How it works

The tool runs in your browser in three steps:

  1. Strip comments and trailing commas. It walks through the text character by character. Inside a string it copies everything up to the closing quote, respecting backslash escapes. Outside strings, // to the end of the line is dropped, and /* … */ is replaced with spaces and its line breaks.
  2. Trailing commas are handled in the same walk: a comma outside a string followed only by whitespace or comments and then } or ] is removed.
  3. Parse and print. The result goes through JSON.parse, then JSON.stringify with your indent. Errors are reported with a line and column from the tool’s own JSON scanner.

Worked examples

These are the tool’s own outputs.

The sample settings file. The // editor settings and /* hide VCS */ comments and both trailing commas disappear, while //not-a-comment inside the URL string stays:

  "files.exclude": {
    "**/.git": true,
    "**/node_modules": true
  },
  "url": "https://toolsrift.com//not-a-comment"

A tsconfig, minified. This JSONC:

{
  "compilerOptions": {
    /* modern output */
    "target": "ES2022",
    "strict": true, // always
  },
  "include": ["src",],
}

becomes {"compilerOptions":{"target":"ES2022","strict":true},"include":["src"]}.

A single-quoted string. A file with // name on line 2 and "a": 'single' on line 3 returns “Invalid JSON at line 3, column 8”, pointing at the single quote. Comments are not the problem there, so the line number matches the original.

Limits and tips

  • The comments are gone for good. Keep the JSONC file as your source and generate the JSON copy when needed.
  • Key order and values are kept, but the formatting is fully rewritten.
  • Duplicate keys are not reported; JSON.parse keeps the last one.

Frequently asked questions

What is JSONC?
JSON with Comments. It is ordinary JSON that also allows // line comments, /* block */ comments and, in most tools, trailing commas. VS Code settings, tsconfig.json, jsconfig.json and devcontainer.json use it. Strict JSON parsers such as JSON.parse reject it.
Is // inside a string treated as a comment?
No. Strings are skipped while comments are removed, so a URL such as https://example.com//path keeps its double slash.
Why does the error point to the right line of my original file?
Block comments are replaced with spaces that keep their line breaks, and line comments keep their newline, so the line and column in an error message match your input.
Does it accept JSON5 features like single quotes or unquoted keys?
No. Only comments and trailing commas are removed. Single-quoted strings, unquoted keys, hex numbers and other JSON5 extras still fail with an "Invalid JSON" message that names the line and column.
Can a string value be changed by mistake?
No. Trailing commas are removed in the same pass that skips strings, so a value such as "a,]" keeps its comma. Only commas outside strings that are followed by } or ] (with nothing but spaces or comments in between) are dropped.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close