ToolzYard Blog

Developer guides and tutorials

JSON Formatting Guide

How to Format JSON Online Without Installing Any Software

Published: March 9, 2026 • Updated: July 10, 2026 • By , Founder of ThreeWorks

Formatting JSON — pretty-printing, beautifying, minifying — is the one JSON operation that is supposed to change nothing. And that is almost true: per RFC 8259, whitespace outside of strings is insignificant, so indentation and line breaks carry no meaning to a parser. But "no meaning to a parser" is not the same as "no consequences." Reformatting rewrites the exact bytes of a document, and a surprising number of systems care about those bytes: signature checks, git diffs, and caches all notice. This guide covers the mechanics of formatting and the places where a harmless-looking reformat quietly bites.

If you just want to clean up a payload right now, paste it into the ToolzYard JSON Formatter. If you want to understand what it is actually doing to your data, read on.

What formatting changes — and what it does not

Formatting adds indentation, line breaks, and a space after each colon and comma. Minifying strips all of it back out. The parsed value is identical either way: the same one-liner and the same indented block deserialize to the same object.

{"name":"John","role":"developer","skills":["json","api","regex"]}

and the pretty version:

{
  "name": "John",
  "role": "developer",
  "skills": ["json", "api", "regex"]
}

Same data, different bytes. That last part is the whole story of this article: formatting changes the byte sequence even though it does not change the value — and some systems are built on the byte sequence, not the value.

The gotcha: reformatting breaks signatures

This is the one that costs people an afternoon. Webhook providers like Stripe and GitHub sign each request by computing an HMAC over the raw request body and sending it in a header (Stripe-Signature, X-Hub-Signature-256). To verify, you recompute the HMAC over the bytes you received and compare.

If your framework parses the JSON and you then re-serialize it before verifying — even with the exact same keys and values — the bytes will differ (spacing, key order, number formatting) and the signature check fails every time. The rule is absolute: verify the signature against the raw, untouched body first, and only parse afterward. The same logic applies to any hash, ETag, or content-addressed store computed over JSON bytes — reformat after hashing, never before.

Two spaces, four spaces, or a tab?

Indentation width is pure convention — the parser does not care — but teams standardize it to keep diffs clean. The most common default is two spaces: it is what JSON.stringify(obj, null, 2) produces, what npm writes into package.json, and what Prettier emits for JSON. Four spaces shows up in Python tooling (json.dumps(obj, indent=4)). Tabs are rarer for JSON but perfectly valid. The rule that matters: pick one and enforce it, because mixing widths across a file turns every future edit into a noisy diff.

A detail worth knowing: JSON.stringify(obj, null, "\t") accepts a string as the third argument, so you can indent with a literal tab or even a custom prefix, not just a number of spaces. Pass a number greater than 10 and it is silently clamped to 10.

Minifying: how much you actually save

Minifying removes every insignificant space and newline. On deeply nested, heavily indented data the savings before compression are real — often 15–30% of the raw byte count, sometimes more, depending on how much whitespace the pretty version carried. That matters for payloads you send on every request or store by the million.

The caveat: if the response is gzip- or brotli-compressed over the wire (most are), repeated indentation compresses extremely well, so the on-the-wire difference between pretty and minified shrinks dramatically. Minify for storage and for uncompressed hot paths; do not assume it is a big win on an already-compressed HTTP response.

Formatting can silently reorder your keys

Most formatters preserve object key order — but not always, and the exception is genuinely surprising. In V8 (Chrome and Node), and per the ECMAScript property-order rules, integer-like string keys are emitted first, in ascending numeric order, ahead of every other key in insertion order. So if your object mixes numeric-looking keys with normal ones:

JSON.stringify({ "b": 1, "2": 2, "a": 3, "1": 4 })
// {"1":4,"2":2,"b":1,"a":3}

The "1" and "2" jumped to the front. This is not a formatter bug — it is how the JavaScript engine orders properties — but it means reformatting a document with numeric keys (common in maps keyed by ID) can reorder it. If anything downstream compares JSON textually, that reordering looks like a change even though no value moved.

Sort keys when you want clean diffs

Two JSON documents can hold identical data yet diff as completely different simply because their keys are in a different order. The fix is to serialize with keys sorted deterministically — alphabetically — so the same data always produces the same text. This is why "sort keys" is a formatter option worth using before you commit generated JSON, snapshot a test fixture, or compare two API responses. A stable key order turns a noisy, unreviewable diff into one that shows only the fields that genuinely changed.

Numbers do not always survive formatting unchanged

Here is the subtle one. Formatting is supposed to preserve values, but round-tripping JSON through a parser and re-serializer canonicalizes numbers. If a formatter parses and reprints (most do), then:

  • 1.0 comes back as 1 — the trailing zero is gone
  • 1e3 becomes 1000, and long decimals are rounded to the nearest value a double can store
  • integers above 253 − 1 can change value, because the parser held them as floats

A pure text formatter that never parses will leave numbers byte-for-byte, but a parse-and-reprint formatter will not. If you are formatting data where the exact numeric spelling matters — financial records, large IDs, anything later hashed — treat "format" as a potentially lossy step, not a purely cosmetic one.

Formatting is not validation

A parse-and-reprint formatter refuses broken input, so a successful format is a decent hint that the syntax is valid. But that is a side effect, not a guarantee: a formatter tells you nothing about whether the shape of the data is correct. Missing fields, wrong types, and duplicate keys all format cleanly. When you need to confirm the data is actually usable, reach for a dedicated validator instead of trusting a clean pretty-print.

Formatting JSON online in practice

The workflow is short: copy the raw payload (from an API response, a log line, browser dev tools, or a config file), paste it into a formatter, and choose your operation — beautify at your team's indent width, minify for storage, or sort keys before a diff. Keep the minified copy for transport and the pretty copy for reading, and do not hand-edit whitespace, since that is exactly how stray trailing commas and broken brackets sneak in.

Conclusion

Formatting JSON is cosmetic to a parser and consequential to everything else. Whitespace is insignificant by the spec, yet reformatting rewrites the bytes — which is why it breaks signatures computed over raw bodies, why it can reorder integer-like keys, and why parse-and-reprint can canonicalize your numbers. Use indentation and key sorting to make data readable and diffable, minify when size genuinely matters, and keep one hard rule in mind: verify signatures and hashes against the original bytes before you ever reformat.

Frequently Asked Questions

Does formatting or minifying JSON change the data?

Not the parsed value — whitespace outside strings is insignificant per RFC 8259, so a minified and a pretty document deserialize to the same object. It does change the exact bytes, which is what matters for signatures, hashes, and text diffs.

Why does reformatting a webhook payload break signature verification?

Providers like Stripe and GitHub sign the raw request body. Re-serializing after parsing produces different bytes (spacing, key order, number formatting), so the recomputed HMAC no longer matches. Always verify the signature against the untouched raw body, then parse.

How much smaller is minified JSON?

Typically 15–30% off the raw byte count for heavily indented data, sometimes more. But indentation compresses extremely well, so over a gzip or brotli connection the real-world difference is much smaller — minification helps most for storage and uncompressed paths.

Can formatting reorder my keys?

Yes. In V8/JavaScript, integer-like string keys ("0", "1", "2") are always emitted first in ascending numeric order, ahead of other keys in insertion order. Reformatting an object with numeric keys can reorder it even though no value changed.

Why should I sort keys before comparing two JSON files?

Identical data with different key order diffs as if everything changed. Serializing with keys sorted alphabetically gives the same data the same text every time, so a diff shows only the fields that genuinely differ — which also keeps generated JSON clean in git.