JSON5 Formatter
Consistent indentation for a JSON5 document, the relaxed syntax left exactly as you wrote it.
JSON5
Formatted
comments droppedA formatter that has to admit what it cannot keep
Reformatting JSON5 works the same way reformatting JSON does: read the document into a value, then print that value back out with consistent spacing. For plain JSON that is the whole story, because plain JSON has nothing else in it. JSON5 is different — the entire reason to reach for it over JSON is // and /* */ comments, unquoted keys, trailing commas and single-quoted strings, and a read-then-print step keeps none of the first one. The JSON5 specification defines all of it, but a parsed value has already thrown the comments away by the time this page ever sees it.
That is a real trade against the format's own reason for existing, and the banner above the editors says so before you paste anything, not after. The json5 package this page runs on — the reference implementation, and what Babel and Jest both depend on for their own config files — has no comment-preserving mode, so there is no cheaper way to keep them here either. If your file leans on comments to explain itself, treat this as a one-way trip: copy the notes out first.
What this page keeps exact is the numbers. JSON5.parse reads an integer through the same IEEE-754 double every JSON parser uses, so a 19-digit ICCID or account number silently rounds — 8901240544102066246 comes back 8901240544102066000 from a plain JSON5.parse/stringify round trip. This page reads the source text directly for any integer a double cannot hold, so the digits you pasted are the digits you get back.
Everything runs in your browser, so nothing you paste — including whatever the comments were protecting you from re-explaining to a teammate — is sent anywhere.
Formatting a JSON5 document
- Paste the document – Unquoted keys, single-quoted strings, trailing commas and comments are all accepted on the way in.
- Read the comment-loss banner once – It stays visible because it applies to every run, not just this one — comments in your input will not be in the output.
- Check the formatted result – Two-space indentation throughout, and every value unchanged — including any integer too long for a JavaScript number.
- Copy or download – The output is still JSON5, not JSON — it keeps unquoted keys and single-quoted strings where the source used them, just reprinted with even spacing.
If a document keeps its comments and you cannot lose them, do not run it through here. Fix indentation in your editor instead. That is the honest trade-off this page is built around, not a limitation it is hiding.
Hand-typed JSON5, evenly indented
A device config with mixed indentation and a trailing comma — the kind of file JSON5 exists for, since none of that is valid JSON.
// device config
{
name: 'edge-gw-04',
iccid: 8901240544102066246,
tags: ['edge','gw',],
}{
name: 'edge-gw-04',
iccid: 8901240544102066246,
tags: ['edge', 'gw'],
}When you need this
Cleaning up a hand-edited config file
A .babelrc.json5 or a webpack config edited by three different people over a year rarely keeps consistent spacing. This tidies the structure — just save a copy of any comments first.
Making a diff readable
A JSON5 file with drifting indentation turns a one-line change into a fifty-line diff. Reformatting first, once, then making the real edit keeps the actual change visible in review.
Checking whether a value survived an edit
Paste before and after versions of a document and compare the reformatted output side by side — consistent spacing makes an actual value change stand out instead of hiding in a whitespace difference.
Confirming a long ID is still exact
Paste a document holding an account or device ID with fifteen or more digits and confirm the formatted output has every digit — the same failure mode as a plain JSON formatter, just for the relaxed syntax.
What this page does
- Reads the source text directly for any integer a JavaScript double cannot hold, so long IDs never round on the way out — see JSON5 to JSON for the same handling in the other direction.
- Keeps the JSON5 syntax on the way out — unquoted keys, single-quoted strings and trailing commas stay JSON5, this does not silently tighten your file into strict JSON.
- States the comment trade-off in the tool itself, not buried in an FAQ answer nobody reads before pasting.
- Runs entirely in your browser, so a config file carrying real credentials or internal hostnames is never sent anywhere.
Questions people actually ask
Why did my comments disappear?
Because formatting means parsing the document into a value and printing that value back out, and a comment is not part of the value — JSON5.parse throws it away before this page ever sees it. No JSON5 tool built on a parse-and-print step can keep them; a genuinely comment-preserving formatter would need a different kind of parser that tracks the original source alongside the value, the way Prettier does for JavaScript.
Does this turn my file into strict JSON?
No — the output is still JSON5. Unquoted keys stay unquoted, single-quoted strings stay single-quoted, and a trailing comma on the last item is kept. If you specifically want strict JSON, use JSON5 to JSON instead.
My 19-digit device ID looks different after formatting elsewhere. Why not here?
Most formatters call the parser's own parse/stringify pair directly, and every JSON5 or JSON parser reads a big integer through a JavaScript number — good for roughly 15 to 16 reliable digits, per IEEE-754 double precision. This page reads the original text for anything longer, so the digits never change.
Can I use this to check whether a file is valid JSON5 at all?
It will refuse to format anything that does not parse, and the error message says roughly where the problem is — but JSON5 Validator is the page built specifically for that, with structural stats and a dedicated invalid-sample button to show what a broken document reports.
Related tools
Specifications and references
- JSON5 — a superset of JSON – The specification, and its rationale for each relaxation over JSON
- The formal JSON5 grammar – The ECMA-404-style grammar the json5 package implements
- json5 on npm – The reference implementation this page runs on
Comments do not survive formatting.This reads your document into a value and prints that value back out, and a comment is not part of the value —
JSON5.parsehas nowhere to put it. If your file leans on comments, copy them somewhere else first, or skip formatting and fix indentation by hand.