Pretty printing (also called beautifying or formatting) turns compact JSON into a readable structure with line breaks and consistent indentation. The data does not change at all; only the whitespace between tokens does. This guide shows what pretty printing does, how to choose an indent style, and how to do it in the browser, on the command line and in code.
APIs usually send JSON minified, on a single line, to save bandwidth:
json{"user":{"id":42,"name":"Asha","active":true},"roles":["admin","editor"]}
Pretty printed with two-space indentation, the same data becomes easy to scan:
json{ "user": { "id": 42, "name": "Asha", "active": true }, "roles": [ "admin", "editor" ] }
Each nested level is indented one step further, every key-value pair gets its own line, and closing braces line up with the line that opened them. That makes it obvious which fields belong to which object.
.json file onto the page.Everything runs locally in your browser, so it's safe to format responses that contain internal data.
The best choice is whichever your project already uses. Consistency matters more than the number, because mixed indentation produces noisy diffs.
If you have jq installed, the identity filter . pretty prints its input:
bashcurl -s https://api.example.com/users/42 | jq .
Python ships with a formatter, so it works on almost any machine:
bashpython3 -m json.tool response.json
Add --indent 2 (Python 3.9+) to change the indent width, or --sort-keys to sort object keys at the same time.
JavaScript's JSON.stringify takes an indent argument:
javascriptconst pretty = JSON.stringify(data, null, 2);
In Python:
pythonimport json pretty = json.dumps(data, indent=2, ensure_ascii=False)
ensure_ascii=False keeps characters such as é or 日本 readable instead of escaping them as é.
If the formatter refuses your input, the JSON is invalid. The most common causes are trailing commas, single quotes and comments. Start with Validate JSON (common errors & fixes).