JSON5 and JSONC Formatter (Keeps Your Comments)

Format and validate JSON with comments, such as tsconfig.json or VS Code settings.json, and JSON5 files. Comments, blank lines and end-of-line notes stay where they are. You can also turn JSON5 into JSONC or into plain JSON. Runs in your browser, so your files are never uploaded.

JSON5 / JSONC Input

Ln 1, Col 1Empty

Formatted

Your result will appear here.
No result yet

Why a Separate Formatter for JSON with Comments?

Standard JSON has no comments, so most JSON formatters, including our main JSON Formatter, remove them or report an error. But many config files are written in JSONC (JSON with Comments) or JSON5, where comments are allowed and often important, like a disabled setting kept for later. This formatter fixes the indentation and checks the syntax while every comment stays in place.

How to Format JSONC or JSON5

  1. Paste your file, drop it on the box, or load it from a link with URL.
  2. Pick the output: JSONC, JSON5, or plain JSON without comments.
  3. Click Format, or press Ctrl + Enter. Errors show the exact line and column.
  4. Copy the result or download it.

Example

Before
{ "compilerOptions": { /* checks */ "strict": true, // all strict checks
"target": "ES2022", }, }
After (JSONC)
{
  "compilerOptions": { /* checks */
    "strict": true, // all strict checks
    "target": "ES2022"
  }
}

JSON vs JSONC vs JSON5

FeatureJSONJSONCJSON5
// line and /* block */ commentsNoYesYes
Trailing commasNoAllowed by most toolsYes
Unquoted keys, like name: 1NoNoYes
Single-quoted stringsNoNoYes
Hex numbers, .5, +1, Infinity, NaNNoNoYes
Strings over several lines (with \)NoNoYes

The JSONC output keeps your comments but writes every key and value in standard JSON form: keys get double quotes, 'text' becomes "text" and 0x1F becomes 31. Use it to turn a JSON5 file into a file that VS Code or TypeScript can read. The JSON5 output only fixes the layout and leaves the syntax as you wrote it.

Where You Meet These Files

  • JSONC: VS Code settings.json, keybindings.json and launch.json; TypeScript's tsconfig.json and jsconfig.json; Deno's deno.jsonc.
  • JSON5: Babel's .babelrc, and apps that read config with the json5 package.
  • Plain JSON only: package.json and API data. A comment there breaks npm and JSON.parse, so use the "Plain JSON" output to strip them.

Tips

  • Comments at the end of a line stay at the end of that line, and blank lines between groups of settings are kept (one at most).
  • Infinity and NaN exist only in JSON5. Choosing JSONC or plain JSON for such a file shows an error instead of quietly changing the value.
  • Want to know why JSON itself has no comments, and the workarounds? Read JSON Comments.
  • Need strict, comment-free JSON checked against a schema? Use the JSON Validator or the JSON Schema Validator.

Frequently Asked Questions

How do I format JSON with comments?

Paste the file into the JSON5 and JSONC Formatter and click Format. It fixes the indentation and checks the syntax while every // and /* */ comment, end-of-line note and blank line between groups stays in place.

What is the difference between JSONC and JSON5?

JSONC is normal JSON plus comments, and most tools also accept trailing commas. JSON5 goes further: unquoted keys, single-quoted strings, hex numbers, Infinity and NaN, and strings over several lines.

Can I convert JSON5 to JSON?

Yes. Choose JSONC to keep the comments and get standard JSON keys and values, or Plain JSON to remove the comments as well. Infinity and NaN cannot be converted, because JSON has no such numbers.

Is my file uploaded?

No. Formatting runs in your browser and your file never leaves your device.

Related Tools