How to use the json beautifier
- Paste compact JSON into the input.
- Open settings and choose 2 spaces, 4 spaces or tabs to match your codebase.
- Turn on Sort keys if you want alphabetical order at every nesting level.
- Press Ctrl/Cmd+Enter to re-run with the new style.
- Copy with Ctrl/Cmd+Alt+C or download a .json file.
Features
- Three indent styles: 2 spaces, 4 spaces or tabs, applied consistently at every level.
- Recursive key sorting: Off by default; when on, sorts objects inside arrays too. Array order never changes.
- No precision loss: Integers above 2^53 and long decimals are kept as written.
- Escape and unescape: Turn a JSON string literal like "{\"a\":1}" back into beautified JSON, or the reverse.
Example
Compact → 4-space indent with sorted keys
Input
{"z":1,"items":[{"y":true,"b":null}],"a":"x"}Output
{
"a": "x",
"items": [
{
"b": null,
"y": true
}
],
"z": 1
}Keys inside the object in the array are sorted too, but the array itself keeps its order because position is meaningful in JSON arrays.
Indent styles and where they are used
| Style | Typical source | Notes |
|---|---|---|
| 2 spaces | JavaScript and TypeScript projects, package.json, Prettier default | Compact; deep nesting stays on screen. |
| 4 spaces | Python json.dumps(indent=4), many Java and C# codebases | Easier to scan levels; wider lines. |
| Tabs | Go-style and editor-configurable teams | Each reader chooses the visual width. |
When to sort keys, and when not to
Sort keys when you store JSON in version control, snapshot tests or fixtures that are generated by code. Generators often emit keys in hash or insertion order, so a regenerated file can show every line as changed even when one value moved. Sorted output keeps diffs down to real changes.
Leave sorting off when order carries meaning for humans, such as package.json (name and version first) or an OpenAPI document, or when the consumer is order-sensitive. JSON objects are formally unordered, but some tools still depend on order.
Matching a style guide
If your repository has an .editorconfig or Prettier config, use the same indent here so pasted output does not produce whitespace noise in review.
JSON Beautifier FAQ
Is a JSON beautifier the same as a JSON formatter?
They produce the same kind of output: line breaks and indentation added without changing data. This page focuses on output style (indent width and key sorting); the main formatter combines that with validation, fixing and secret scanning.
Should I use 2 or 4 spaces for JSON?
Either is valid. Match your project; most JavaScript projects use 2 spaces and many Python projects use 4. Tabs are fine if your team prefers them.
Why sort JSON keys alphabetically?
Sorted keys make two versions of the same object line up, so diffs in code review or Git show only real changes, and generated files become reproducible.
Does sorting keys change array order?
No. Only object keys are sorted. Array items keep their positions because order is part of an array's meaning.
How do I pretty print JSON from the command line?
Use jq '.' file.json, jq -S '.' to sort keys, or python -m json.tool --indent 4 file.json. Note that Python and jq may round very large integers, which this page does not.
How do I beautify an escaped JSON string?
If the text looks like "{\"a\":1}" with backslashes, use Unescape first to turn it back into JSON, then format it.

