InfyCalculator
💻

JSON Formatter Calculator

Beautify JSON with 2- or 4-space indentation, or minify it to a single line — with a validity check and a structure summary.

JSON
Mode
Indent
Loading calculator…

How it works

beautify = JSON.stringify(value, null, indent) · minify = JSON.stringify(value) · both first validate by JSON.parse

JSON has one grammar but two everyday shapes: an indented, line-broken form that people read, and a whitespace-free form that machines send. This tool parses the input first — which is the real validity check, since a single missing comma or unquoted key makes it unparseable — then re-serializes it. Beautifying adds newlines and 2 or 4 spaces of indentation per level; minifying removes every optional space and newline. Because it round-trips through a parser, the output is always canonical JSON: keys keep their order, but trailing commas, comments and single quotes (none of which are legal JSON) are rejected with the parser’s own error message.

Worked example

The compact object {"name":"InfyCalc","tags":["fast","free"],"count":42,"nested":{"ok":true}} is valid JSON: a top-level object with 4 keys, 74 characters when minified. Beautified with 2 spaces it becomes a multi-line, indented block with "tags" and "nested" opened out one level in; minifying it again returns the original single line.

Sources: JSON.stringify() — MDN

Frequently asked questions

Does formatting change my data?

No — only the whitespace between tokens changes. Object keys, array order, numbers and strings are all preserved exactly. Beautify and minify are perfectly reversible; they never add, drop or reorder any value.

Why does it reject JSON that "looks fine"?

Strict JSON forbids trailing commas, comments, single-quoted strings and unquoted keys — all common in JavaScript object literals but not in JSON. The parser reports the exact position it choked on, which is usually where one of those crept in.

Should I send minified or beautified JSON?

Minify for anything that travels — APIs, storage, config sent over the network — because it is smaller and parses identically. Beautify only for reading and debugging. Compression (gzip) narrows the size gap, but minified still wins on payload and parse time.

Related calculators

This calculator is for educational purposes. Double-check important results before acting on them.