JSON Formatter

Format and pretty-print JSON with 2, 4 or custom-space indentation and optional key sorting. Paste minified JSON, get readable output. Nothing is uploaded.

Loading tool…

Worked examples

  • Minified JSON pasted from an API response

    The most common case: a single-line API response becomes readable, indented JSON without changing any values.

  • 4-space indent for a nested object

    Some codebases standardize on 4-space JSON; the indent size is a real formatting decision, not cosmetic noise.

  • Sorting keys alphabetically for a stable diff

    Sorting keys recursively makes two JSON payloads with the same data but different key order diff cleanly in git or a code review.

What this tool does

This formatter takes JSON in any layout — minified, inconsistently indented, or pasted straight out of a browser's network tab — and rewrites it with consistent indentation. It parses the text first, so the output is guaranteed to be valid JSON holding the same data as the input; only whitespace changes, plus key order if you turn on sorting. The one exception is number formatting, covered below.

When you need it

  • An API response or log line arrives as one long unbroken line and you need to actually read its structure.
  • You're comparing two JSON payloads and want them indented the same way before eyeballing the difference.
  • You're about to paste JSON into documentation or a bug report and want it to look intentional rather than dumped.
  • You want a stable, sorted representation of a JSON object so that two semantically identical payloads with different key order produce an identical diff.

Rules the formatter applies

  1. The JSON is parsed, not just re-indented. This means genuinely invalid JSON is rejected with an error rather than being "formatted" into something that still doesn't parse.
  2. Indentation width is your choice — 2 spaces is the most common convention in JavaScript and JSON-heavy tooling; 4 spaces shows up in some Python- and Java-adjacent codebases.
  3. String, boolean and null values are never changed; numbers are re-serialised. The text is parsed into JavaScript numbers and written back out, so 1.0 becomes 1, 1e3 becomes 1000, and an integer too large for a double (like 12345678901234567890) is rounded to the nearest representable value. Strings keep their exact characters.
  4. Key order is preserved by default, matching the order keys appeared in the source, with one JavaScript quirk: keys that are whole numbers ("1", "2") are always moved to the front in ascending order. Turning on "sort keys" recursively reorders every object's keys alphabetically, including nested ones.

What sorting keys is for

Two JSON documents that describe the same data can still fail to diff cleanly if their key order differs — which happens constantly when different code paths or library versions serialize an object. Sorting keys before comparing removes that noise, so the diff shows only real content changes. It's a one-way, informational transform: don't sort keys in JSON your application actually depends on being ordered a particular way (rare, but true for things like ordered maps serialized as JSON).

Things to check after formatting

  • If the source had duplicate keys at the same level, JSON.parse silently keeps only the last one — the formatted output won't show you that a key was dropped, so check the raw input if the record count looks short.
  • Very large numbers (larger than JavaScript's safe integer range, about 9 × 10^15) can lose precision during parsing; if your JSON carries 64-bit IDs as bare numbers rather than strings, verify them separately.
  • Trailing whitespace or a byte-order mark at the start of the pasted text won't affect parsing but can be worth trimming from the source file itself.

Limits

Input is capped at 2 MB. For genuinely enormous JSON files, format a representative excerpt instead — the full file will still parse and format correctly but may be slow to render in a browser textarea.

Frequently asked questions

Is my JSON uploaded anywhere?
No. Formatting runs entirely in your browser; nothing is sent to a server.
Does formatting change my data?
No, values are untouched. Only whitespace changes (plus key order if you turn on sort-keys), with one exception: numbers are re-serialised, so 1.0 becomes 1 and integers beyond 2^53 lose precision. Object keys that are whole numbers are also listed first, in ascending order.
What happens if my JSON is invalid?
The tool stops and shows the parser's error message so you can find and fix the problem before formatting.
Why sort keys?
Two JSON documents with the same data but different key order show up as a noisy diff. Sorting the keys in both first removes the reordering, so the diff shows only real changes.