Beautify JSON in one click, or in one line of code
JSON Pretty Print
Paste compact JSON or open a .json file and pretty print it with 2 spaces, 4 spaces or tabs. Prefer to do it in code? Copy a ready-made one-liner for Python, JavaScript, jq or your terminal below.
Tip: Ctrl + Enter runs Pretty Print JSON
Valid JSON
121 B1 linedepth 3Processed in your browser
What does pretty printing JSON mean?
Pretty printing, also called beautifying or prettifying, adds line breaks and indentation to JSON so that every property sits on its own line and nested objects are indented under their parent. The data does not change. Only the whitespace between tokens does, which is why pretty-printed and minified JSON parse to exactly the same value.
This JSON beautifier validates your text first, then writes it out with the indentation you choose. You can also sort keys alphabetically, which is handy when comparing two documents.
How to pretty print JSON online
- 1
Add JSON
Paste compact JSON or press Open file. The example in the editor is a single line you can try.
- 2
Pick indentation
Choose 2 spaces, 4 spaces or tabs, and tick Sort keys if you want properties in A to Z order.
- 3
Pretty print
Press Pretty Print JSON. Errors, if any, are shown with their line and column and a suggested fix.
- 4
Copy or save
Copy the beautified JSON or download it as a .json file.
How to pretty print JSON in code
Every major language can pretty print JSON with its standard library. Use these when you need it in a script, a test or a terminal.
| Language or tool | Pretty print code |
|---|---|
| JavaScript / Node.js | JSON.stringify(data, null, 2) |
| Python | json.dumps(data, indent=2) |
| Python (terminal) | python -m json.tool data.json |
| jq | jq . data.json |
| curl + jq | curl -s https://api.example.com/items | jq . |
| PHP | json_encode($data, JSON_PRETTY_PRINT) |
| Go | json.MarshalIndent(data, "", " ") |
| Java (Jackson) | mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data) |
| C# (System.Text.Json) | JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true }) |
| PowerShell | Get-Content data.json | ConvertFrom-Json | ConvertTo-Json -Depth 10 |
Pretty print options
- 2 spaces
- The default in most JavaScript tooling and the most compact readable layout.
- 4 spaces
- Matches many Python, Java and C# codebases and makes deep nesting easier to follow.
- Tabs
- Lets each reader set their own indentation width in their editor.
- Sort keys
- Orders properties A to Z at every level, like Python's sort_keys=True or jq -S.
Pretty printed vs minified JSON
| Pretty printed | Minified | |
|---|---|---|
| Best for | Reading, reviewing, debugging, docs | Sending over the network, storing |
| Line breaks | One per property or item | None |
| Size | Larger | 20 to 30% smaller |
| Same data? | Yes | Yes |
What formatting can change
Formatting and minifying parse your JSON and write it back out, so the data stays the same but a few representation details can change. Duplicate property names collapse to the last value, integer-like keys such as "10" move ahead of other keys, and numbers beyond 9,007,199,254,740,991 can lose precision. Keep long numeric IDs as strings, and keep your original file when byte-for-byte output matters.
JSON Pretty Print FAQ
Is pretty printing the same as beautifying JSON?
Yes. Pretty print, beautify and prettify all mean adding indentation and line breaks to make JSON readable. None of them change the data.
How do I pretty print JSON in Python?
Use json.dumps(data, indent=2) in code, or run python -m json.tool data.json in a terminal. Add sort_keys=True to order keys alphabetically.
How do I pretty print JSON in JavaScript?
Call JSON.stringify(data, null, 2). The third argument sets the indentation: a number of spaces, or a string such as "\t" for tabs.
How do I pretty print JSON in the terminal?
Pipe it into jq: cat data.json | jq . or curl -s URL | jq . If jq is not installed, python -m json.tool works on any machine with Python.
Can I choose the indentation width?
Yes. Choose 2 spaces, 4 spaces or tabs before pressing Pretty Print JSON. Change it and press the button again to re-indent.
Does pretty printing sort keys?
Not unless you tick Sort keys. Without it, properties keep their original order, except integer-like keys, which JavaScript always places first.