JSON Pretty Print Online
Paste minified or one-line JSON and get indented, readable output. Pick 2 spaces, 4 spaces or tabs.
What pretty printing changes
Only whitespace outside strings. Each value moves to its own line, nested objects and arrays are indented one level deeper, and a space follows every colon. Keys, values, order and string contents stay exactly as they were.
{"id":42,"name":"Ada","roles":["admin","editor"],"settings":{"theme":"dark","beta":true}}{
"id": 42,
"name": "Ada",
"roles": [
"admin",
"editor"
],
"settings": {
"theme": "dark",
"beta": true
}
}How to pretty print JSON in code
When the JSON is already in a script, terminal or log, these one-liners give the same result as the tool above.
JavaScript / Node.js
The third argument of JSON.stringify is the indent: a number of spaces or a string such as "\t".
const pretty = JSON.stringify(JSON.parse(text), null, 2);
// Pretty print an object in the browser console
console.log(JSON.stringify(data, null, 2));Python
indent turns on pretty printing. ensure_ascii=False keeps non-English text readable instead of \u escapes.
import json
print(json.dumps(data, indent=2, ensure_ascii=False))
# From the shell, no code needed
python -m json.tool input.jsonCommand line (jq)
jq pretty prints with 2 spaces by default. Use --indent 4 or --tab to change it.
jq . input.json
jq --indent 4 . input.json > pretty.jsoncurl API response
Pipe the response body into jq. -s hides the progress bar so only JSON reaches jq.
curl -s https://api.example.com/users/1 | jq .Go
json.MarshalIndent takes a prefix for every line and the indent string.
out, err := json.MarshalIndent(data, "", " ")Java (Jackson)
Jackson's default pretty printer uses 2 spaces and puts a space before each colon.
String pretty = new ObjectMapper()
.writerWithDefaultPrettyPrinter()
.writeValueAsString(data);PHP
Combine flags with |. JSON_UNESCAPED_SLASHES keeps URLs readable.
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);More Python detail, including writing UTF-8 files and sorting keys, is in how to pretty print JSON in Python.
Related tools
- JSON beautifier: the full formatter with validation, repair and tree view.
- Minify JSON: the reverse, back to compact one-line JSON.
- JSON viewer: browse large documents as a collapsible tree.
- Fix invalid JSON: when pretty printing reports a syntax error.
Frequently Asked Questions
What does it mean to pretty print JSON?
Pretty printing rewrites JSON with line breaks and indentation so each key, value and nesting level is easy to see. The data does not change: a parser reads pretty printed and minified JSON identically.
Is pretty print the same as beautify or format?
Yes. Pretty print, prettify, beautify and format all describe the same operation. The opposite is minify, which removes the whitespace again.
Should I use 2 spaces, 4 spaces or tabs?
Use whatever the project already uses. 2 spaces is the common default in JavaScript, jq and most APIs. 4 spaces matches Python's usual style. Tabs let each reader choose their own width in the editor.
Why does my pretty print fail?
Pretty printing parses the JSON first, so any syntax error stops it. Common causes are a trailing comma, single quotes, unquoted keys, or a truncated response. The error message shows the line and column to fix.
Is my JSON uploaded anywhere?
No. Formatting runs in JavaScript in your browser. Pasted text and uploaded files stay on your device.