On this page

Strict JSON allows neither comments nor trailing commas. JSONC allows comments; whether it accepts trailing commas depends on the program reading it. The JSONC to JSON mode on 4all.tools accepts both extensions, removes them, and validates the output. Check what format your destination requires: if it needs JSON, convert the document and keep the commented original.

A configuration accepted by your editor can fail when sent to an API that requires strict JSON. Renaming .jsonc to .json does not transform the content: the comments and commas remain.

How JSON, JSONC, and JSON5 differ

Syntax Strict JSON JSONC JSON5
Comments using // or /* ... */ No Yes Yes
Comma after the last property or element No Depends on the consumer Yes
Single-quoted strings No No Yes
Unquoted keys No No Yes, for supported identifiers

The grammar in RFC 8259 defines strict JSON. The JSONC draft specification makes trailing comma support optional. In this tool, JSONC mode accepts them in both objects and arrays. That does not guarantee another JSONC consumer will accept them.

Convert a commented configuration step by step

Save a copy of the original. This input is valid for the JSONC mode on 4all.tools:

{
  // URL used in the test environment
  "endpoint": "https://api.example.test/v1",
  "note": "The text /* demo */ must be preserved",
  "retries": 3,
  "regions": ["mx", "es",],
}
  1. Open JSON Repair and paste the sample into Input text.
  2. Choose JSONC to JSON.
  3. Select Convert to run the operation. Pasting or changing the mode does not start conversion.
  4. Review the proposed output, changes, and warnings. Check the values against the original.
  5. If the result is valid and matches the data you need, select Copy output and use that version at your destination.

Expected result, formatted for readability:

{
  "endpoint": "https://api.example.test/v1",
  "note": "The text /* demo */ must be preserved",
  "retries": 3,
  "regions": ["mx", "es"]
}

The current engine produces these data and validates the candidate as strict JSON. The layout above is editorial: the actual conversion replaces comments and trailing commas with spaces and preserves line breaks. You may see a blank line where the comment was and spaces before closing brackets or braces.

What is removed and what stays intact

The sample loses three pieces of text:

  • The line comment beginning with // URL.
  • The comma after "es", before ].
  • The comma after the array, before }.

The // in https://api.example.test/v1 and the text /* demo */ inside the string are data and stay intact. So do the number 3, its numeric type, and the array order: "mx" first, then "es". Avoid a global regular expression replacement to delete comments: it can remove parts of a URL or literal text.

Losing comments is deliberate. If they contain instructions for maintaining the configuration, keep the JSONC original and generate a JSON copy for the consumer that requires it.

If conversion still fails

Read the diagnostic before changing modes. A missing comma, an unclosed string, or an unfinished block comment remains an error. For missing separators or closing delimiters, see how to find and fix JSON syntax errors, then convert again after making the necessary edit.

This input is outside JSONC mode:

{ environment: 'test' }

It has an unquoted key and a single-quoted string. Its strict JSON equivalent is:

{"environment":"test"}

These constructs exist in JSON5; removing comments does not convert them. Repair JSON can attempt to fix some cases using heuristics, but it is not a complete JSON5 converter. Enable it only when you need that repair and can review each inference: valid syntax does not prove that the intended data was recovered.

For an AI response, see how to review AI-generated JSON before using it, with examples of wrappers and truncated values.

The tool also applies size and complexity limits and rejects duplicate keys. These are product policies, not a universal definition of JSONC. If you encounter a limit, reduce the input; if keys are duplicated, decide which value to keep. The JSON Repair page lists the current limits.

Share this guide

Article link