Back to Blog

JSON Pretty Print: Format and Beautify JSON Data

Mar 3, 20264 min read

Minified JSON is compact and efficient for machines, but it's nearly impossible to read when you're debugging or reviewing data. Pretty printing adds consistent indentation and newlines to transform a single compressed line into a human-readable structure.

What Pretty Print Does

Before (minified)
{"user":{"id":1,"name":"Alice","roles":["admin","editor"]}}
After (pretty printed)
{
  "user": {
    "id": 1,
    "name": "Alice",
    "roles": [
      "admin",
      "editor"
    ]
  }
}

Pretty Print Online (Fastest)

The quickest method requires zero code. Paste your JSON into our JSON Pretty Print tool, choose your indent size (2 or 4 spaces), and press Ctrl+S. The formatted output appears instantly — fully client-side, so your data never leaves the browser.

Pretty Print with JavaScript / TypeScript

JavaScript
const data = { user: { id: 1, name: 'Alice', roles: ['admin', 'editor'] } };

// The third argument controls indent (number = spaces, string = custom)
console.log(JSON.stringify(data, null, 2));   // 2-space indent
console.log(JSON.stringify(data, null, 4));   // 4-space indent
console.log(JSON.stringify(data, null, '\t')); // tab indent

Pretty Print with Python

Python
import json

data = {"user": {"id": 1, "name": "Alice", "roles": ["admin", "editor"]}}

# indent=2 for 2-space indentation
print(json.dumps(data, indent=2))

# Reading from a file and pretty-printing
with open('data.json') as f:
    obj = json.load(f)
print(json.dumps(obj, indent=2, sort_keys=True))

Pretty Print from the Command Line

Terminal
# Python built-in (no install)
cat data.json | python3 -m json.tool

# jq (install: brew install jq / apt install jq)
jq '.' data.json

# Node.js one-liner
node -e "process.stdout.write(JSON.stringify(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')),null,2))" < data.json

Pretty Print vs. Minify: When to Use Each

Use caseRecommended format
Debugging / code reviewPretty print (2 or 4 spaces)
Production API responsesMinified
Config files committed to gitPretty print (readable diffs)
LLM / AI promptsMinified (fewer tokens)
Logs read by humansPretty print

Catch Parse Errors While Formatting

Our pretty print tool doubles as a validator. If your JSON has a trailing comma or a missing bracket, it highlights the exact line with an error message before formatting. Great for catching problems in API responses.

Pretty Print Your JSON Instantly

Paste minified or messy JSON and get a beautifully formatted result in one click. No sign-up required.