DevToolPal
EN

JSON5 to JSON Converter

Convert JSON5 or JSONC (comments, trailing commas, unquoted keys, single quotes) to strict, standard JSON.

Runs locally, never uploaded

Options

Indent

Input

0 chars · 0 B

Output

0 chars · 0 B

What it does

JSON5 is an extension of JSON designed for files that people write by hand. It allows comments, trailing commas, unquoted object keys, single-quoted strings and a few friendlier number formats. Tools such as Babel, some bundlers and many applications accept JSON5 or JSONC (JSON with comments, used by tsconfig.json and VS Code settings) for configuration.

Many parsers, APIs and languages only accept strict JSON, though. This converter reads JSON5 or JSONC and prints standard JSON that any JSON parser accepts: every key in double quotes, no comments, no trailing commas, and numbers in decimal form.

How to use it

  1. Paste your JSON5 or JSONC, upload a .json5, .jsonc or .json file, or click Sample.
  2. Choose the Indent: 2 or 4 spaces, or Compact for a single line.
  3. Choose what to do with Infinity and NaN: convert them to null, convert them to strings, or show an error.
  4. Copy or download the JSON.

If the input has a syntax error, the message shows the line and column so you can jump straight to it. Plain JSON is valid JSON5, so you can also use the tool to check that a file parses and to re-indent it.

Example

This JSON5 configuration:

// Server settings
{
  host: 'localhost',
  port: 0x1F90,      // 8080
  ratio: .5,
  tags: ['api', 'v2',],
}

becomes this strict JSON:

{
  "host": "localhost",
  "port": 8080,
  "ratio": 0.5,
  "tags": [
    "api",
    "v2"
  ]
}

The comments are removed, the keys and strings get double quotes, the hexadecimal number and the leading decimal point are written in decimal, and the trailing commas disappear.

What gets converted

  • // line comments and /* */ block comments are removed.
  • Unquoted keys such as port and single-quoted strings such as 'localhost' become double-quoted.
  • Strings continued with a backslash at the end of a line are joined into one string.
  • Hexadecimal (0xFF), leading or trailing decimal points (.5, 5.) and explicit plus signs (+3) become plain decimal numbers.
  • Trailing commas in objects and arrays are dropped.
  • If a key appears twice, the last value wins, as in JavaScript.

FAQ

› What is the difference between JSON5 and JSONC?

JSONC is JSON plus comments (and, in VS Code, trailing commas). JSON5 goes further: unquoted keys, single-quoted strings, multi-line strings, hexadecimal numbers, leading or trailing decimal points, Infinity and NaN. JSON5 is a superset of JSONC, so this tool reads both.

› Are my comments kept?

No. Standard JSON has no comment syntax, so comments are removed. If you need to keep them, keep the JSON5 file as the source and generate the JSON from it.

› What happens to Infinity and NaN?

Strict JSON cannot represent them. By default they become null, like JavaScript's JSON.stringify. You can turn them into strings instead, or show an error that names the exact path.

› Is my data uploaded?

No. Parsing and conversion run entirely in your browser, so configuration files with secrets never leave your device.