How to format JSON depends on where it is. If you have it on the clipboard, paste it into a browser formatter such as AyeTab's JSON Formatter. If it is a file, use your editor's format command, and if it is coming out of a command, pipe it through jq.
This guide covers each case in a few lines, plus what to do when the JSON will not format at all.
Why this comes up so often
Developers who track AI coding usage read a lot of JSON. Coding agents and CLIs keep their settings in JSON files, usage and billing APIs answer in JSON, and exported logs are often JSON or JSON Lines. Almost all of it is written for machines, on a single line. Formatting is the first step to reading it.
Option 1: in the browser
This is the quickest route for a snippet you copied from a terminal, a dashboard or an API response.
- Open the AyeTab JSON Formatter.
- Paste. The page formats and checks the JSON as you paste it.
- Fix any error it reports, then copy the result, or press Minify to get one line back.
AyeTab parses the text in the browser tab and does not upload it, which matters when the JSON includes API keys, account IDs or usage data you would rather keep private. There is no signup, it is free, and it works offline once loaded. If you do this daily, the AyeTab Chrome extension keeps the formatter on your new tab page and in a side panel.
Option 2: in your editor
When the JSON is already a file, format it where it is.
- VS Code: Shift+Alt+F on Windows, Shift+Option+F on a Mac, Ctrl+Shift+I on Linux, or Format Document from the right-click menu.
- Other editors: most have a format or reformat command, built in or through a plugin. Check your editor's documentation for the shortcut.
This keeps the change in the file itself, so you can commit it.
Option 3: in the terminal
jq pretty-prints by default, so the simplest command is:
cat settings.json | jq .
Use jq --indent 4 . for four spaces, jq --tab . for tabs and jq -c . to compact it to one line. If jq is not installed, Python ships a formatter:
python -m json.tool settings.json
Which option to pick
| Where the JSON is | Fastest way | Changes the file |
|---|---|---|
| Clipboard | AyeTab JSON Formatter in the browser | No |
| A file you are editing | Editor format command | Yes |
| Output of a command | jq or python -m json.tool | Only if you redirect it |
Two spaces, four spaces or tabs
The indent width is a team choice, not a rule of JSON. Any width parses the same way, because whitespace outside strings carries no meaning. What matters is that a repo uses one style everywhere, so diffs show real changes instead of reindented lines. If your project has a formatter config, let the editor apply it. For a quick read of a one-off payload, whatever the browser tool or jq produces is fine, since you will not commit it.
When it will not format
A formatter has to parse JSON before it can indent it, so invalid input fails. Check these first:
- A trailing comma after the last item.
- Keys or strings in single quotes instead of double quotes.
- Comments, which standard JSON does not allow.
- A file that is actually JSON Lines, one object per line. Format a single line at a time, or pass the file to jq, which reads one JSON value after another.
When another tool is the better choice
If you want a collapsible tree to explore a large response, a site with a tree view such as jsonformatter.org can help, as long as the data is not sensitive. For everything else, the three options above cover it.