DevTools Logo

JSONC to JSON Converter

JSONC to JSON Converter

Strip comments and trailing commas from JSON-with-comments without touching strings.

Runs in your browser
Try an example

JSONC input

Strict JSON

No JSON to convert yet

Paste JSONC or load an example.

A string-aware tokenizer removes // line comments and /* block */ comments without touching comment markers inside quoted strings, then drops trailing commas before closing braces and brackets. Choose pretty, minified or as-is output. If the result is still invalid JSON, the tool reports the line and column in your original input and flags common JSON5 constructs such as unquoted keys, single quotes and hex numbers.

Examples

Commented tsconfig

Input
{ // compiler
 "compilerOptions": { "strict": true, }, }
Output
{"compilerOptions":{"strict":true}}

Comments and both trailing commas are removed without changing values.

URLs are string content

Input
{"url": "https://example.com//x"}
Output
{"url":"https://example.com//x"}

The double slash is inside a string, so the tokenizer leaves it untouched.

Comment before a trailing comma

Input
{ "a": 1, /* note */ }
Output
{"a":1}

The comment disappears and the comma before the closing brace is dropped.

Original error coordinates

Input
{
  "a": 1 /* missing brace */
Output
Error with original line and column

Errors are mapped back to the input you pasted, not to the stripped intermediate text.

About this tool

JSONC to JSON Converter turns JSON-with-comments — the format used by tsconfig.json and many editor settings — into strict JSON that any parser accepts. A tokenizer walks the input character by character, tracking string and escape contexts, so comment markers inside URLs and quoted values are preserved exactly.

After comments are removed, a second string-aware pass drops trailing commas before closing braces and brackets, including cases where a comment sat between the comma and the closing character. You can emit pretty-printed JSON, minified JSON, or the cleaned text with its original whitespace.

If the cleaned document is still invalid, the error is reported with a line and column mapped back to your original input. Common JSON5 constructs — unquoted keys, single-quoted strings, hex numbers and unusual decimal points — produce specific hints instead of a generic failure. Conversion runs entirely in the browser.

What this tool does not do

  • Only JSONC comments and trailing commas are supported; JSON5 syntax is reported but not rewritten.
  • Unterminated block comments are ignored to the end of input rather than reported as a separate error.
  • Error positions depend on the error message format of the host JavaScript engine.
  • A leading byte order mark is removed with a warning; other BOM positions are not special-cased.
  • Input is capped at 5 MB to keep the browser responsive.

How to use this tool

  1. Paste JSONC

    Paste a config file with // or /* */ comments, or load one of the examples.

  2. Pick an output mode

    Pretty is readable, minified is compact, and as-is keeps the original whitespace minus comments and trailing commas.

  3. Read the stats and hints

    The tool counts comments and trailing commas removed and flags JSON5-only syntax.

  4. Copy or download

    Copy the strict JSON or download it as a .json file for your build pipeline.

Use cases

Unblock a build

Strip comments from a config that a strict JSON parser refuses to read.

Prepare shared fixtures

Convert annotated JSONC examples into portable strict JSON.

Debug config errors

See the original line and column of a syntax error after comments are removed.

Teach JSON dialects

Demonstrate the difference between JSONC comments and JSON5 syntax additions.

Supported and unsupported syntax

InputHandling
// line commentRemoved; the following newline is kept
/* block comment */Removed, including multi-line blocks
"//" inside a stringPreserved verbatim
Trailing comma before } or ]Removed
Single-quoted stringsNot supported — JSON5 hint shown
Unquoted keysNot supported — JSON5 hint shown
Hex numbersNot supported — JSON5 hint shown

JSONC is JSON plus comments and trailing commas. JSON5 adds many more features this tool deliberately does not rewrite.

Common mistakes

Mistake:Using a regex like s,//.*,,g to strip comments.

Fix:It destroys URLs and any string containing //. Use a string-aware tokenizer like this one.

Mistake:Assuming JSONC accepts single quotes.

Fix:Single quotes, unquoted keys and hex numbers are JSON5. The tool reports them as hints rather than silently converting.

Mistake:Forgetting trailing commas can remain after comment removal.

Fix:The second pass removes them; check the trailing-comma count in the stats strip.

Mistake:Expecting the as-is mode to reformat values.

Fix:As-is only removes comments and trailing commas; choose pretty or minified to change formatting.

Mistake:Trusting errors from the stripped text.

Fix:Positions are mapped back to the original input offsets, which is why the reported line and column match what you pasted.

Frequently asked questions

Why do regex strippers break URLs?

A pattern like //.* to end-of-line does not know whether it is inside a quoted string, so https://example.com becomes https:. This converter tracks string and escape state, leaving quoted content byte-for-byte intact.

Does it handle // and /* inside strings?

Yes. Both markers are only treated as comments in code context. Inside a string they are copied verbatim, including escaped quotes and Unicode text.

What JSONC features are not supported?

JSONC here means JSON plus comments and trailing commas. JSON5 features — single-quoted strings, unquoted keys, hex numbers, leading or trailing decimal points and extra commas — are detected and reported as hints, but not rewritten.

Where does it report errors?

After stripping, the result is parsed with JSON.parse. If that fails, the character position is mapped through recorded offsets back to the line and column of your original input.

Is my config uploaded anywhere?

No. Tokenization, cleaning, validation and formatting all happen in your browser. Nothing is uploaded or stored.

What does the as-is output mode do?

It keeps the original whitespace and formatting while removing comments and trailing commas. Choose pretty or minified if you also want to reformat the document.

References & standards