JSON Formatter — Beautify JSON Online
Format and beautify JSON in your browser. Paste compact JSON, choose 2- or 4-space indent, optionally sort keys, then copy or download the readable result.
Everything runs in your browser. Press Ctrl/Cmd+Enter format.
0 characters · 0 lines · 0 bytes
How to Format JSON Online
- Paste minified JSON or upload a file.
- Choose 2-space or 4-space indent. Optionally sort keys.
- Click Format JSON, then copy or download the readable result.
- If nothing happens, the payload is not valid JSON. Check it in the JSON validator and fix the reported line, then format again.
- Turn on Sort keys before you save a fixture or a config file, so the next diff shows only real changes.
About This JSON Formatter
This formatter exists to beautify JSON — not to be a full editor. Create or rewrite files in the JSON editor. Check a broken payload in the JSON validator. Compact it again with the JSON minifier.
Pretty-printing only changes whitespace so nested objects and arrays are easy to scan. Sorting keys reorders object keys alphabetically (including nested objects) without changing values.
Formatting is the fastest way to make an unreadable API response tractable. A production payload usually arrives as a single line that can run to thousands of characters, and finding one nested field inside it by eye is close to impossible. Adding indentation turns that wall of text into a tree you can scan: each nesting level steps in by two or four spaces, every array element starts on its own line, and the shape of the data becomes obvious in a couple of seconds.
Indent size is mostly a house-style decision. Two spaces is the default in most JavaScript and TypeScript projects, in npm package.json files, and in the majority of REST API documentation, because it keeps deeply nested structures from marching off the right-hand edge of the screen. Four spaces is easier on the eye for shallow config files and reads more clearly in slide decks and printed documentation. Both parse identically — no parser anywhere treats them differently — so pick one and apply it consistently across a repository rather than mixing the two.
Sorting keys is the underrated half of this tool. JSON objects have no meaningful key order as far as the specification is concerned, but every serializer emits them in some order, and that order tends to drift as code changes. When you sort alphabetically before committing a fixture or a config file, two versions of the same document line up row for row, so a diff shows only the values that actually changed instead of a scramble of moved lines. It is the single cheapest way to make JSON fixtures reviewable in a pull request.
There are limits worth knowing. Formatting is a whitespace operation and nothing more: it will not repair a trailing comma, it will not add the quotation marks that a JavaScript object literal leaves off its keys, and it will not tell you whether the document matches a schema your API expects. Numbers are re-emitted exactly as the parser read them, which means a value written with a very large number of significant digits can lose precision on the round trip — that is a property of JSON numbers being IEEE 754 doubles, not of this page. If precision matters, transmit such values as strings.
If the input will not format at all, the syntax is broken rather than merely ugly. The JSON validator reports the exact line and column of the first failure, which is almost always faster than re-reading the payload yourself. Once it parses, come back here to beautify it, or send it straight to the JSON to CSV converter or the JSON to TypeScript converter.
Frequently Asked Questions (FAQ)
How do I format JSON online?
Paste JSON, pick an indent, and click Format JSON. The output is pretty-printed in place so you can copy or download it.
What is the difference between format, beautify, and minify JSON?
Format and beautify mean the same thing here: add indentation and line breaks for readability. Minify removes unnecessary whitespace to shrink the payload.
What indent should I use for JSON?
2 spaces is the usual default for APIs and JavaScript projects. 4 spaces is a readability preference. Both parse the same.
Can I sort JSON keys while formatting?
Yes. Sort keys reorders object keys alphabetically, including nested objects. Values stay the same.
Does this JSON formatter upload my data?
No. Formatting runs entirely in your browser. Nothing is sent to a server.
What if the JSON will not format?
It is invalid. Use the JSON validator to see the error line, fix the syntax, then format again. JSON examples can give you a known-good starting point.
Does formatting JSON change the key order?
Not unless you switch Sort keys on. By default the formatter preserves the order the keys arrived in and only adds whitespace. With Sort keys on, every object is reordered alphabetically, including nested objects, which makes two versions of the same file diff cleanly.
Can I format a large JSON file?
Yes, within the limits of your browser tab. Formatting happens locally, so the ceiling is your available memory rather than an upload limit. Files in the low megabytes are comfortable on a normal laptop. Very large exports are better handled by a streaming tool such as jq, because the whole document has to be held in memory here.
Why does the output differ from my editor's formatter?
Editors apply their own conventions — some keep short arrays on one line, some align colons, some preserve blank lines between blocks. This page emits the canonical output of JSON.stringify with your chosen indent, which is the same result most build tools and language runtimes produce. If your team has a house style, run the repository formatter after pasting the result back.
Will formatting fix a trailing comma or a single-quoted key?
No. Those are syntax errors, and formatting only rearranges whitespace in JSON that already parses. JSON is stricter than a JavaScript object literal: keys must use double quotes, strings cannot use single quotes, and no comma may follow the last element. Fix the syntax first, then format.
Should I commit formatted or minified JSON to git?
Commit the formatted version. Line-based diffs are useless on a one-line file — a single character change shows the whole document as modified. Formatted JSON with sorted keys produces a readable diff a reviewer can actually approve. Minify at build or request time instead, where the size matters and nobody reads it.
Does pretty-printing change the meaning of the data?
No. Whitespace between tokens carries no meaning in JSON, so the parsed value is identical before and after. The one thing to watch is numeric precision: JSON numbers are IEEE 754 doubles, so a value with more significant digits than a double can hold is already rounded by the time any formatter sees it. Send such values as strings if exactness matters.
Tips for Readable JSON
- Format API responses before you hunt for a nested field.
- Sort keys when you are comparing two configs by eye.
- Minify only after you have confirmed the formatted version is correct.
- Pick one indent width per repository and stick to it. Mixed 2- and 4-space files create noisy diffs every time someone reformats on save.
- Sort keys before you commit a test fixture. A reviewer then sees only the values that changed, not a reshuffle of lines that moved.
- Keep the formatted copy for humans and generate the compact copy at build time. Do not maintain both by hand — they will drift apart.
- If the payload is huge, format a representative slice rather than the whole export. You rarely need all 40,000 records to understand the shape.
- Paste two formatted payloads into the text diff checker to see exactly which fields an API changed between two releases.