FormatterHQ

JSON5 Formatter

Pretty-print JSON5 config files with consistent quotes and indentation, sort keys, validate the syntax, or convert JSON5 to standard JSON for tools that only read JSON.

Input JSON5
Output JSON5
Ready.

How to use the JSON5 Formatter

  1. Paste your JSON5, upload a .json5 file, or click Sample.
  2. Choose the Indent, the String quotes (single or double) and whether to Sort keys.
  3. Click Format JSON5, or use Convert to JSON for strict JSON output and Validate for a syntax check.
  4. Copy or download the result.

What this JSON5 formatter does

JSON5 extends JSON with the conveniences of JavaScript object literals, which makes it pleasant for hand-written configuration. This JSON5 formatter parses such a file and prints it again in a consistent style, or converts it into standard JSON when another program needs to read it.

JSON5 features at a glance

  • Comments: // line and /* block */.
  • Trailing commas in objects and arrays.
  • Unquoted keys when the key is a valid identifier, and single-quoted strings.
  • Numbers written as 0x1F90, .5, 5., +3, Infinity and NaN.
  • Strings split over several lines with a backslash at the end of each line.

Example

// server settings
{
  host: 'localhost',
  port: 0x1F90, // 8080
  ratio: .5,
  retries: +3,
  timeout: Infinity,
  "log-level": "debug",
  paths: ['/api', '/admin',],
}

Format JSON5 with the defaults (2 spaces, single quotes) gives:

{
  host: 'localhost',
  port: 8080,
  ratio: 0.5,
  retries: 3,
  timeout: Infinity,
  'log-level': 'debug',
  paths: [
    '/api',
    '/admin',
  ],
}

Look closely at what changed. Keys that are valid identifiers are unquoted and log-level, which contains a hyphen, keeps its quotes. Numbers are normalized: the hex value is written in decimal, .5 becomes 0.5 and the plus sign is dropped. Every multi-line object and array ends with a trailing comma, which keeps future diffs to one line.

Comments are not preserved

The formatter parses the file into data and prints the data again, so comments are dropped, as you can see above. If your comments matter, format a copy, or use the output only to check structure and indentation. The same applies to the original number spelling: 0x1F90 is stored as the number 8080.

Options

  • Indent – 2, 3 or 4 spaces or a tab.
  • String quotes – single quotes (the default) or double quotes for all strings and for keys that need quoting.
  • Sort keys – orders keys alphabetically at every level, ignoring case, while arrays keep their order.

The quote setting is applied to every string, and the chosen quote character is escaped where it appears inside a value. With single quotes, "it's" is written as 'it\'s'; with double quotes it stays "it's". If your text has many apostrophes, double quotes keep it cleaner.

Duplicate keys are allowed by the parser, but only the last value survives: {a: 1, a: 2} is formatted as {a: 2}. Formatting is therefore a quick way to spot a key that was accidentally defined twice in a long config.

Convert JSON5 to JSON

Convert to JSON outputs strict JSON: all keys double-quoted, no comments and no trailing commas. JSON has no representation for Infinity or NaN, so those values become null; in the example, "timeout": null. Check such fields before relying on the converted file.

Validate checks the syntax and says whether the document is also valid strict JSON. For a page dedicated to checking files, with a list of typical errors, see the JSON5 validator.

JSON5, JSON or YAML?

JSON5 suits configuration that people edit by hand and a JavaScript toolchain reads. For data exchanged between services, stick to plain JSON and format it with the JSON formatter. If you want comments plus a more compact syntax, compare with YAML in the YAML formatter.

Formatting and conversion run in your browser; the file is not uploaded unless you use Load URL or Save & Share.

Frequently asked questions

Why did my comments disappear?
The formatter parses JSON5 into data and writes the data back out, and comments are not part of the data. Keep a copy of the original if you need the comments, or add them back after formatting.
What happens to Infinity and NaN when converting to JSON?
Standard JSON has no way to write them, so they are converted to null. If the value matters, change it to a large number or a string in the JSON5 source before converting.
Can I format regular JSON with this tool?
Yes. Every valid JSON document is also valid JSON5. Formatting it here produces JSON5 style output with unquoted keys and trailing commas; use Convert to JSON to keep it strict.
Does the formatter keep hexadecimal numbers?
No. Hex, leading-dot and plus-signed numbers are read as numeric values and printed in plain decimal form, such as 8080 for 0x1F90.
Which file extension does JSON5 use?
The usual extension is .json5. Some tools also read JSON5 syntax from files named .json or from specific config names, so check the documentation of the tool that consumes the file.

Last updated October 3, 2026

Related tools