Why JSON with comments exists
The official JSON specification (RFC 8259) does not allow comments. That was a deliberate choice by Douglas Crockford — his intent was a pure data-interchange format, not a configuration language. But in practice, configuration files want comments: a reader needs to know why a setting is there, not just what its value is.
So a dialect called JSONC (JSON with Comments) emerged. VS Code uses it for settings.json, TypeScript uses it for tsconfig.json, and many build tools accept it in their config files. It adds two features to JSON: // and /* */ comments, and trailing commas after the last element of an object or array.
The problem: most JSON parsers (browsers, libraries, APIs) reject JSONC outright. JSON.parse() throws on the first comment. If you want to feed JSONC into a system that expects strict JSON, you have to strip the comments first — that's what this tool does.
What this tool removes
- Line comments —
//through end of line, including inline trailing comments on the same line as a value. - Block comments —
/* ... */across any number of lines. Unterminated block comments remove everything to end of input. - Trailing commas — the comma after the last item in an object or array. Toggleable — disable if your target parser accepts them.
Strings are fully respected. A URL like "https://example.com" or a message like "see /* below */" is preserved verbatim — only comments outside strings are stripped. Escaped quotes inside strings are tracked so the scanner never breaks out early.
When you'll actually reach for this
- Feeding
tsconfig.jsoninto a tool that wants strict JSON. Many CI pipelines and Node scripts callJSON.parse()directly on a tsconfig and fail until the comments are gone. - Copying a VS Code
settings.jsonsnippet into a JSON validator. The file is JSONC by design but external tools usually aren't. - Preparing a configuration blob for an API that accepts only JSON. Webhook payloads, GraphQL variables, or REST request bodies almost always need strict JSON on the wire.
- Cleaning up a JSON example copy-pasted from a blog post or documentation page where the author added explanatory
// ...notes.
After stripping, pipe the result through our JSON Formatter for a pretty-printed, validated version.
JSONC vs JSON5 vs HJSON
Several "JSON with more stuff" dialects exist. They're easy to confuse:
- JSONC — JSON + comments + trailing commas. That's it. Most widely supported because the delta is small. VS Code, TypeScript, and most build tools speak it.
- JSON5 — a larger extension: comments, trailing commas, single-quoted strings, unquoted keys, hex numbers,
Infinity/NaN, and more. More ergonomic but less universally supported. - HJSON — human-friendly JSON with optional quotes, multiline strings, and comments. Used less often in tooling but some configs accept it.
This tool targets JSONC specifically — the most common "JSON with comments" dialect in practice. It will also strip comments out of JSON5, but won't translate single-quoted strings or unquoted keys to strict JSON.
Related JSON tools on CodeBoxTools
- JSON Formatter — validate and pretty-print the cleaned JSON after stripping comments.
- JSON Viewer — explore the result as an interactive tree.
- JSON Compare — diff two JSON documents side by side.
- JSON Stringify & Escape — compact JSON to one line or escape it for embedding in a string.