Pretty Print JSON Online: Format and Beautify JSON Instantly
Last updated:
Pretty printing JSON adds indentation and line breaks to a compact string, turning a minified blob into a readable document. Online formatters handle this instantly: paste up to several MB of JSON, choose 2-space or 4-space indentation, and get formatted output in under 200ms — no account, no install. Every formatter runs the same algorithm: parse, then re-serialize with JSON.stringify(data, null, 2) (indent 2) or json.dumps(data, indent=4) in Python. This guide covers indent options (2 spaces, 4 spaces, tabs), pretty-printing from the command line with jq ., sorting keys for reproducible output, and minifying JSON back to a single line.
Paste your JSON into Jsonic's JSON Formatter for instant pretty printing with syntax highlighting and tree view.
Pretty print JSON nowWhat pretty printing does
A minified JSON string packs all data onto one line with no whitespace. Pretty printing expands it so each key-value pair sits on its own line, nested objects are indented, and the structure becomes immediately readable.
// Minified — hard to read
{"user":{"name":"Alice","role":"admin","tags":["api","internal"]},"active":true}
// Pretty printed — 2-space indent
{
"user": {
"name": "Alice",
"role": "admin",
"tags": [
"api",
"internal"
]
},
"active": true
}The data is identical. Only whitespace changes. JSON parsers treat both forms exactly the same.
How to pretty print JSON online
- Open Jsonic's JSON Formatter.
- Paste your JSON string into the left panel — or upload a
.jsonfile. - Click Format. The right panel shows the pretty-printed result with 2-space indentation.
- Click Copy to copy the formatted JSON, or Download to save it as a file.
The formatter also validates syntax as it formats. If your JSON has an error — a trailing comma, missing bracket, or wrong quote style — it shows the exact line and character before formatting.
Indent size options
The JSON specification accepts any whitespace between tokens. The common conventions are:
| Indent | Typical use |
|---|---|
| 2 spaces | JavaScript, web APIs, most linters |
| 4 spaces | Python json.dumps default, Java |
| Tab | Some config files, Go json.MarshalIndent |
2 spaces is the safest default for any JSON that will be committed to a repository or shared in documentation.
Pretty print JSON in JavaScript
Use JSON.stringify with a space argument to pretty print in code:
const data = { user: { name: 'Alice', role: 'admin' }, active: true }
// 2-space indent
console.log(JSON.stringify(data, null, 2))
// 4-space indent
console.log(JSON.stringify(data, null, 4))
// Tab indent
console.log(JSON.stringify(data, null, '\t'))See the pretty print JSON in JavaScript guide for replacer functions, custom serialisers, and browser DevTools shortcuts.
Pretty print JSON in Python
import json
data = {"user": {"name": "Alice", "role": "admin"}, "active": True}
# Pretty print to console
print(json.dumps(data, indent=2))
# Pretty print a JSON file
with open("data.json") as f:
parsed = json.load(f)
print(json.dumps(parsed, indent=2))
# Sort keys alphabetically while formatting
print(json.dumps(data, indent=2, sort_keys=True))Python's json.tool module also works directly from the terminal — see the format JSON in Python guide for the full command.
Pretty print JSON from a cURL response
Pipe a cURL response through python3 -m json.tool or jq to pretty print API responses in the terminal:
# Using Python (available on most systems)
curl -s https://api.example.com/users | python3 -m json.tool
# Using jq (install separately)
curl -s https://api.example.com/users | jq '.'Frequently asked questions
What does pretty print JSON mean?
Pretty printing adds indentation and line breaks so each key-value pair is on its own line and nested objects are visually indented. The data is identical — only the whitespace changes.
Is pretty-printed JSON valid JSON?
Yes. JSON parsers ignore whitespace outside string values, so a pretty-printed file and a minified file are semantically identical and interchangeable.
What is the difference between pretty print and beautify?
They mean the same thing. "Beautify", "pretty print", and "format" all refer to adding indentation and whitespace to make JSON human-readable. Some tools also call this "format" or "indent".
Does pretty printing change the JSON data?
No. Only whitespace outside of string values is added. The keys, values, types, and structure are unchanged. Parsing a pretty-printed file produces the exact same object as parsing the minified original.
How do I pretty print a JSON file from the command line?
Use jq or Python's json.tool module. With jq (install via Homebrew: brew install jq): jq '.' input.json prints the file with 2-space indentation. With Python: python3 -m json.tool input.json prints with 4-space indentation by default. To change the indent: python3 -m json.tool --indent 2 input.json (Python 3.9+). Both commands validate the JSON and report an error if the file is invalid.
Why is my pretty-printed JSON not sorting keys alphabetically?
Pretty printing preserves insertion order by default. To sort keys in Python: json.dumps(data, indent=2, sort_keys=True) sorts all keys alphabetically at every nesting level. In JavaScript, JSON.stringify does not sort keys natively — build a sorted object first or use a library. In Jsonic's formatter, enable the Sort Keys option before clicking Format.
Format your JSON in one step
Paste any JSON string — minified, malformed, or deeply nested — into Jsonic's JSON Formatter. It pretty prints, validates, and lets you explore the structure in a tree view.
Open JSON FormatterRecommended reading
- Designing Data-Intensive Applications (2nd Edition) — Martin Kleppmann & Chris RiccominiThe modern classic on data systems — encoding formats, schemas, replication, and stream processing.
- JavaScript: The Definitive Guide (7th Edition) — David FlanaganThe complete reference for the language JSON came from — serialization, async, and the full standard library.
As an Amazon Associate, Jsonic earns from qualifying purchases.