DevKits

JSON5 / JSONC to JSON Converter — Strip Comments & Trailing Commas

Convert JSON5 or JSONC to strict RFC 8259 JSON online. Strips // and /* */ comments, single quotes, unquoted keys, trailing commas, hex numbers, and NaN / Infinity. 100% local.

Last updated:

353 chars · 14 lines
No output yet.

Error after stripping JSON5 extensions: Expected property name or '}' in JSON at position 7 (line 3 column 3)

Line 3, column 3

Paste JSON5 or JSONC (with comments, single quotes, unquoted keys, trailing commas, hex numbers, or NaN / Infinity) on the left to get strict RFC 8259 JSON on the right. NaN / Infinity are rewritten as null; everything else is a lossless transformation.

What is JSON5 → JSON?

JSON5 and JSONC are two popular supersets of JSON. JSONC adds only comments and is used by VS Code, tsconfig, and .prettierrc. JSON5 goes further and permits single quotes, unquoted object keys, trailing commas, hex integers, leading / trailing decimal points, and IEEE 754 special values. Both formats are strictly incompatible with the built-in JSON.parse — feeding them directly to a strict parser produces an unhelpful error. This tool strips the incompatible extensions in a single pass, respecting string and comment boundaries, and re-serializes the result through JSON.stringify so the output is guaranteed spec-compliant.

How to convert JSON5 / JSONC to strict JSON

  1. 1Paste your JSON5 or JSONC document into the left editor.
  2. 2The right pane instantly renders strict JSON with the extensions removed.
  3. 3If a stray character survives the strip pass, the error location (line and column) points at it inside the intermediate output so you can trace it back.
  4. 4Copy the strict JSON, or switch to Tree view for a structural preview.

Tips & Best Practices

  • For tsconfig / VS Code settings, prefer the dedicated jsonc-parser npm package server-side — it preserves comments as trivia if you need to write the file back.
  • JSON5 numbers include hex (0xff) and leading dot (.5). This tool converts them to their decimal equivalents (255 and 0.5) — semantically identical, syntactically JSON-legal.
  • If your source contains NaN or Infinity as intentional signals, replace them with sentinel strings ('NaN') before conversion to avoid the lossy null coercion.

Frequently Asked Questions

What's the difference between JSON5 and JSONC?

JSONC (JSON with Comments) is a strict-JSON superset that only adds // and /* */ comments — used by VS Code (tsconfig.json, .vscode/*.json). JSON5 is a larger superset that additionally allows single quotes, unquoted keys, trailing commas, hex numbers, and NaN / Infinity. This tool accepts both.

How are NaN and Infinity handled?

Standard JSON cannot represent NaN or Infinity — the tool rewrites both (and -Infinity) to null. If those values are semantically important, encode them as strings in your source before conversion.

Does it validate the input against JSON5 grammar?

No — it's a permissive one-pass stripper. Any deviation the tool can safely rewrite is rewritten; anything it can't produces a JSON.parse error at the reported line and column so you can fix the source.

Can I round-trip JSON back to JSON5?

No. Comments, unquoted keys, and hex numbers are one-way information — they exist in JSON5 but not in JSON. You can, of course, re-pretty-print the JSON output afterwards.

Is my input uploaded anywhere?

No. All parsing and stripping runs entirely in your browser as client-side JavaScript.

Related Tools