Pretty print JSON from the command line and in code
# Python (no install needed)
python -m json.tool data.json
# jq
jq . data.json
// JavaScript
JSON.stringify(data, null, 2)
// PHP
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
To minify instead, use jq -c . or JSON.stringify(data) with no extra arguments.
Two spaces, four spaces or tabs
JSON does not care about indentation, so pick what your project already uses. Two spaces is the most common style in JavaScript projects and in most API documentation. Four spaces is common in Python and Java code. Tabs make the file a little smaller and let each reader choose the width. For files kept in Git, a stable format also gives cleaner diffs, so format before you commit.
Read JSON with the tree view
A long API response is easier to read as a tree than as text. Fold the objects you do not need, open the one you care about, and click a key to get its JSONPath, ready to use in code or in the JSONPath box. This is the quickest way to answer questions like “where in this response is the user’s email?” without scrolling through thousands of lines.
Formatting changes the layout, never the data
Formatting only adds or removes whitespace between tokens. Keys stay in the same order, strings keep their exact characters, and numbers are not rounded. That is why a formatted file and its minified copy parse to the same value. If you see different data after formatting, the input was not valid JSON to begin with: for example, a duplicate key, where most parsers keep only the last value.