Skip to content
Tools

JSON Beautifier (Pretty Print JSON)

Last updated:

To beautify JSON, paste it here and pick an indent style: 2 spaces, 4 spaces or tabs. Turn on Sort keys to order every object alphabetically, which makes two versions of the same file diff cleanly in Git.

Beautifying happens in your browser tab; the text is never sent anywhere. How we protect your data

Input

Loading editor…

Paste JSON here

or drop a .json file anywhere in this box. Everything stays in your browser.

Output

Paste JSON to see it as a table.
Loading editor…
Paste JSON, drop a file, or try the sample.

How to use the json beautifier

  1. Paste compact JSON into the input.
  2. Open settings and choose 2 spaces, 4 spaces or tabs to match your codebase.
  3. Turn on Sort keys if you want alphabetical order at every nesting level.
  4. Press Ctrl/Cmd+Enter to re-run with the new style.
  5. 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

Indent styles and where they are used
StyleTypical sourceNotes
2 spacesJavaScript and TypeScript projects, package.json, Prettier defaultCompact; deep nesting stays on screen.
4 spacesPython json.dumps(indent=4), many Java and C# codebasesEasier to scan levels; wider lines.
TabsGo-style and editor-configurable teamsEach 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.

Related tools