Why Minified JSON Is Unreadable
APIs almost always return JSON with all whitespace stripped to save bandwidth — a response with fifty nested fields shows up as one continuous line of text. That's fine for a machine to parse but useless for a human trying to spot which field holds the value they need. Formatting (also called "pretty-printing") re-indents that same data into a readable tree without changing a single byte of actual content.
Formatting JSON on the Command Line with jq
jq is the standard tool for this on Linux and macOS (and available on Windows via winget or Scoop). Pipe any JSON response straight through it with no filter argument to pretty-print:
curl -s https://api.example.com/users/42 | jq .
That single trailing . is jq's identity filter — it means "output the whole input, unmodified except for formatting." The result is indented, syntax-colored (in a terminal that supports color), and much easier to scan:
{
"id": 42,
"name": "Sachin Siju",
"roles": [
"admin",
"editor"
],
"active": true
}
jq isn't just a formatter — it's a full query language, which is where it earns its keep beyond simple pretty-printing:
# Extract a single field
curl -s https://api.example.com/users/42 | jq '.name'
# Filter an array of objects to those matching a condition
curl -s https://api.example.com/users | jq '.[] | select(.active == true)'
# Pull out just the fields you care about into a flatter shape
curl -s https://api.example.com/users/42 | jq '{id, name}'
Formatting JSON from a File
If you've already saved a minified response to disk, point jq at the file directly instead of piping:
jq . response.json > response_formatted.json
python3 -m json.tool response.json or cat response.json | python3 -m json.tool. It's not as powerful for querying, but it's on every machine with Python already installed.Formatting JSON in VS Code
For JSON you're inspecting as part of active development work, VS Code's built-in formatter is often faster than switching to a terminal:
- Paste the minified JSON into a new file and save it with a
.jsonextension (this activates JSON-aware formatting). - Press Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS) to format the whole document.
VS Code also gives you a collapsible tree — click the small chevrons in the gutter next to any { or [ to fold that section, which is genuinely useful for a response with deeply nested or repetitive array data you don't need to see in full right now.
Formatting JSON in the Browser
When you're inspecting an API response directly from a browser request (Network tab in DevTools), most modern browsers format JSON responses automatically when you open the request URL directly. In Firefox and Chrome, navigating straight to a JSON API endpoint renders a built-in collapsible JSON viewer with search — no extension required. If a response isn't rendering that way (some servers return it with a non-JSON content-type), open DevTools, go to the Network tab, click the request, and view the Response or Preview tab, which formats it regardless of the declared content-type.
Validating Along the Way
A formatter will typically error out loudly on invalid JSON rather than silently producing garbage — which makes it a useful validation step too. If jq . throws a parse error, you've likely got a trailing comma, unescaped quote, or a response that isn't actually JSON (some APIs return an HTML error page with a 200 status when something goes wrong upstream, and that will fail to parse as JSON immediately, which is a useful signal on its own).
Wrap-Up
Reformatting minified JSON is a solved problem with several equally good options depending on where you're already working: jq . on the command line for anything you're piping through curl, VS Code's built-in formatter for files you're editing, and the browser's native JSON viewer for quick inspection of a live API response. Pick whichever fits your current workflow, and reach for jq specifically once you need to filter or extract fields rather than just read them.
Discussion & Insights