Format JSON on a Mac Without Pasting It Into a Website
You have a minified JSON blob and you want to read it. The reflex is to search “json formatter”, paste it into the first result, and click Format.
Stop and think about what that action is. You just uploaded that JSON to a server you know nothing about. If it was an API response, it may have carried a bearer token, a session ID, a customer email, an internal hostname, or a Stripe object with real amounts in it. Most online formatters are honest tools with an ad unit. Some log input. You can’t tell which from the outside, and “it’s just a config file” is exactly the assumption that leaks credentials.
Your Mac can already do this locally, in several ways, none of which involve a network request.
The one-liner you should memorize
macOS ships Python, and Python has a JSON formatter built in:
pbpaste | python3 -m json.tool
pbpaste reads your clipboard, json.tool pretty-prints it, and the result lands in your
terminal. No installation, no network, works on a stock Mac.
Two useful details:
- It preserves key order by default. Your keys come out in the order they went in. Add
--sort-keysif you’d rather have them alphabetized. - It validates as a side effect. Invalid JSON produces a parse error naming the line and column, which makes this a fast way to find the trailing comma you’re hunting.
jq, which may already be installed
jq is the sharper tool, and on recent macOS versions Apple ships it:
ls /usr/bin/jq && /usr/bin/jq --version
On the Mac this was written on, that prints jq-1.7.1-apple. If your macOS is older and
the file isn’t there, brew install jq gets it.
Basic formatting is the identity filter:
pbpaste | jq .
But the reason to reach for jq over json.tool is that it does more than indent:
pbpaste | jq '.items | length' # how many items?
pbpaste | jq '.data[].email' # pull one field from every element
pbpaste | jq 'del(.token, .password)' # strip secrets before sharing
pbpaste | jq -c . # compact it back down
That third one is worth noting. If you do need to send someone a JSON payload, del()
lets you remove the sensitive fields locally first, which is a much better habit than
pasting the whole thing anywhere.
Make it a shell function
Formatting the clipboard and putting it back on the clipboard, formatted, is the operation
you actually want most often. Add this to ~/.zshrc:
# fj — format the JSON on the clipboard, in place
fj() {
local out
if ! out=$(pbpaste | jq . 2>&1); then
printf 'invalid JSON: %s\n' "$out" >&2
return 1
fi
printf '%s' "$out" | pbcopy
printf '%s\n' "$out"
}
Run fj, and your clipboard now holds the formatted version, ready to paste anywhere. On
invalid input it prints jq’s error and leaves your clipboard untouched rather than
overwriting it with an error message — which is the failure mode of the naive one-liner
version of this.
Reload with source ~/.zshrc and it’s available in every new shell.
In an editor
If the JSON is already in a file, your editor almost certainly formats it:
- VS Code: ⇧⌥F formats the document. JSON support is built in, no extension needed.
- Xcode: works for JSON files, though it’s a heavy thing to open for a snippet.
- BBEdit / Nova / Sublime: all have JSON formatting, some behind a menu item rather than a shortcut.
The catch is the same as always: this helps once the content is a file. Getting it into a file is the friction, which is the whole subject of creating a text file quickly on a Mac.
Formatted on paste, in one step
The workflows above are all “get it somewhere, then run something on it.” The step can be collapsed: have the file arrive already formatted.
That’s what I built Effunde to do, so read this section knowing I’m the author. Click the menu bar icon, choose JSON, and a small editor opens with your clipboard already pasted and already run through Prettier — indented and readable before you’ve done anything else. Same for HTML, CSS, JavaScript, YAML, and Markdown. Then save it wherever you want, or don’t save it at all if you only needed to read it.
It’s $1.99, it does nothing over the network with your content, and the formatting happens on your Mac.
What to pick
For occasional use, pbpaste | python3 -m json.tool is genuinely all you need and it’s
already installed — I’d start there and not spend money. If you slice JSON often, learn jq
properly; it’s the better investment than any GUI. If you’re formatting pasted content many
times a day and want it to happen without a command, that’s when a tool earns its keep.
The only option I’d actively avoid is the one most people reach for first: the website.