JSON Pretty Print
Format and beautify minified JSON. Paste your JSON below:
What is Pretty Printing?
Pretty printing (also called beautifying) adds whitespace, indentation, and line breaks to JSON to make it human-readable. Minified JSON saves bandwidth but is nearly impossible to read. Pretty printing solves this.
Before (minified)
{"name":"John","age":30,"address":{"city":"New York","zip":"10001"}}After (pretty printed)
{
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": "10001"
}
}How to Use
- Paste your JSON — Minified or already formatted
- Choose indentation — 2 spaces (common), 4 spaces, or 1 space
- Optional: Sort keys — Alphabetize object keys
- Copy or download — Use the formatted result
The tool formats automatically as you type. You can also click "Format JSON" to manually trigger formatting.
Formatting Options
Indentation
- 2 spaces — Most common, used by JavaScript/TypeScript projects
- 4 spaces — Common in Java, Python, and some style guides
- 1 space — Compact but readable
The JSON specification doesn't mandate any particular indentation. Choose what matches your project's style guide or personal preference.
Sort Keys
Enable "Sort keys alphabetically" to reorder object keys A-Z. This helps with:
- Comparing two JSON files (consistent ordering)
- Finding specific keys quickly
- Cleaner version control diffs
For more sorting options, try our dedicated JSON Sorter.
Pretty Print in Code
Most JSON libraries support pretty printing. Here's how to do it programmatically:
JavaScript
// Format with 2-space indentation
const formatted = JSON.stringify(obj, null, 2);
// The third argument is the indent:
// - number: spaces (2, 4, etc.)
// - string: literal indent ("\t" for tabs)Python
import json
# Format with 2-space indentation
formatted = json.dumps(obj, indent=2)
# With sorted keys
formatted = json.dumps(obj, indent=2, sort_keys=True)Command Line (jq)
# Pretty print a file
cat data.json | jq '.'
# Pretty print with sorted keys
cat data.json | jq -S '.'Why Pretty Print JSON?
- Debugging — Quickly understand API responses and data structures
- Documentation — Create readable examples for docs and tutorials
- Code review — Make JSON changes easier to review
- Learning — Understand nested structures visually
- Configuration — Keep config files readable
Pretty Print vs Minify
These are opposite operations:
| Pretty Print | Minify |
|---|---|
| Adds whitespace | Removes whitespace |
| Human-readable | Machine-optimized |
| Larger file size | Smaller file size |
| For development/debugging | For production/transfer |
Need to compress JSON instead? Use our JSON Minify tool.
Related Tools
- JSON Validator — Validate and format JSON with error detection
- JSON Minify — Compress JSON by removing whitespace
- JSON Sorter — Sort keys with more options
- Benefits of JSON Beautification — Learn more
Frequently Asked Questions
What's the difference between pretty print and beautify?
Nothing — they're the same thing. "Pretty print," "beautify," and "format" all refer to adding indentation and line breaks to make JSON readable.
Does pretty printing change the data?
No. Pretty printing only adds whitespace. The actual data (keys, values, structure) remains identical. The formatted JSON is semantically equivalent to the minified version.
What indentation should I use?
2 spaces is the most common convention, especially in JavaScript ecosystems. Use 4 spaces if your project style guide requires it. The choice is purely cosmetic — it doesn't affect the data.
Can I pretty print invalid JSON?
No. The JSON must be valid to be formatted. If you have invalid JSON, this tool will show an error message indicating what's wrong. Fix the syntax error first, then format.
Common Mistakes & Pro Tips
- Pretty-printing is purely cosmetic — Beautifying only inserts whitespace and line breaks between tokens; it never changes the parsed value, validity, or meaning of the JSON. A pretty-printed document and its minified form are byte-different but semantically identical, so JSON.parse() returns the same object for both.
- Whitespace is insignificant outside strings — Per RFC 8259, spaces, tabs, and newlines are only allowed between structural tokens, never inside the characters of a string value. That is why indentation is safe: it lives between keys, values, commas, and brackets, but the contents of your string literals are left untouched.
- Tabs vs. spaces is a style choice, not a correctness one — JSON.stringify(value, null, 2) uses two spaces, null, '\t' uses a tab, and any string up to 10 characters becomes the indent unit. Pick one to match your repo's existing files; parsers accept all of them equally.
- Beautifying does not validate beyond parseability — If the tool successfully pretty-prints, the input was valid JSON, because formatting requires parsing first. But it cannot catch semantic problems like a wrong schema, duplicate keys collapsing, or numbers that exceed safe integer precision.
- Large numbers may silently lose precision — JavaScript parses JSON numbers as IEEE 754 doubles, so an integer above 2^53-1 (such as a 64-bit ID) can be rounded when the document is parsed for formatting. If you must preserve exact large integers, keep them as quoted strings in your source data.
Frequently Asked Questions
Does pretty-printing change my data?
No. It only adds indentation and newlines between tokens to make the structure readable. The underlying values, key names, and types are exactly the same, and a program parsing the output gets an identical object to parsing the original.
What is the difference between pretty-print and minify?
They are inverse operations on the same value. Pretty-print adds whitespace for human readability; minify strips all insignificant whitespace to make the smallest possible payload for network transfer or storage. Both produce valid JSON that parses to the same thing.
How do I choose between 2 spaces, 4 spaces, and tabs?
Match whatever convention your project already uses so diffs stay clean. Two spaces is the most common default in the JavaScript ecosystem and what most config files use; four spaces or tabs are equally valid. The choice has zero effect on how the JSON parses.
Why does my formatted output reorder or drop keys?
A pure pretty-printer should preserve key order and all keys. If keys disappear, your input contained duplicate keys, and the JSON parser kept only the last occurrence of each, which is standard JavaScript behavior. Check the source for accidentally repeated keys.
Can I format a file that has comments or trailing commas?
Not as strict JSON. RFC 8259 JSON allows neither comments nor trailing commas, so a strict formatter will report an error. Those features belong to JSON5 or JSONC; remove them first or use a tool that explicitly targets those dialects.
Is my JSON uploaded anywhere when I format it?
No. This tool runs entirely in your browser using JavaScript, so the text you paste is parsed and re-serialized locally on your device. Nothing is sent to a server, which makes it safe for sensitive or proprietary data.