Developer and Text Tools

JSON5 and JSON with Comments: How to Convert Them to Strict JSON

What JSONC and JSON5 add to JSON, why strict parsers reject them, and how to convert config files to plain JSON or back without losing your data.

Saizul Amin
Saizul Amin3 Nov 2026 · 3 min read
JSON5 and JSON with Comments: How to Convert Them to Strict JSON

Open a tsconfig.json or your editor's settings file and you will often find comments and trailing commas. Feed the same file to Python's json module, jq or a strict API, and it fails. The file is not broken; it is written in a relaxed dialect. This guide explains the two common dialects and how to move between them and strict JSON.

Strict JSON in one paragraph

JSON, defined in RFC 8259, allows objects, arrays, double-quoted strings, numbers, true, false and null. Keys must be double-quoted strings. There are no comments and no comma after the last item. Numbers are decimal only, with no leading zeros, no plus sign and no Infinity or NaN. The rules are strict on purpose, so every parser agrees.

JSONC: JSON with comments

JSONC is strict JSON plus // line comments and /* */ block comments. Most tools that accept it also allow trailing commas. TypeScript, VS Code and many editors read configuration files this way, which is why those files look like JSON but are not quite.

JSON5: JSON for humans

JSON5 goes further and borrows from JavaScript:

  • single-quoted strings and unquoted keys such as target: 'ES2022'
  • trailing commas in objects and arrays
  • hexadecimal numbers like 0x1F, a leading plus sign, and decimals like .5 or 5.
  • Infinity, -Infinity and NaN
  • strings continued on the next line with a backslash

It is convenient for files people edit by hand, and some build tools use it for configuration.

Why conversion is not just deleting comments

Removing comments with a regular expression is tempting and wrong. A URL such as "http://example.com" contains //, and a glob such as "src/**/.ts" contains /. A correct converter understands strings, so it only removes comments outside them. For JSON5 the job is bigger: quotes, keys and numbers all have to be rewritten. That needs a real parser.

Converting with the tool

The JSON5 and JSONC to JSON Converter offers three outputs.

  1. To strict JSON parses the whole JSON5 grammar and writes standard JSON. Choose an indent, or zero for minified output, and optionally sort keys alphabetically to make two configs easy to compare.
  2. To JSON5 writes the friendlier form: unquoted keys where that is safe, single or double quotes, and optional trailing commas.
  3. Strip comments only keeps your file exactly as it is apart from the comments, and optionally the trailing commas. Line breaks stay, so line numbers in later error messages still match the original file.

Each run also lists the non-JSON features found, such as four comments, four trailing commas and one hex number. If the list is empty, the input was strict JSON already. Duplicate keys are reported, because the last one silently wins and that often explains a setting that seems to be ignored.

Infinity and NaN

These values have no strict JSON form. You can turn them into null, which is what JSON.stringify does, write them as strings, or make the conversion stop with an error so nothing changes silently. For configuration, stopping is usually the safest choice.

A typical workflow

Keep the human-friendly file with comments in your repository, because comments explain why a setting exists. During a build or in a CI script, convert it to strict JSON for tools that need it. Never edit the generated file by hand; regenerate it instead.

Errors that point to the right place

When a file cannot be read, the converter reports the line and column where reading stopped, for example an unclosed string, a missing comma or a forbidden leading zero such as 01. Fix it, and the result updates immediately.

Summary

JSONC and JSON5 make configuration pleasant to write, and strict JSON keeps machines in agreement. Use a proper parser to move between them, keep comments in the source file, and generate strict JSON where tools require it.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages