Pretty Print JSON on the Mac Clipboard: json_pp and a Hotkey
Pretty print JSON on the Mac clipboard with pbpaste | json_pp | pbcopy, or one hotkey in Bytepliers with undo. Includes fixes for a blanked clipboard.
GuideUpdated 6 min read
On this page
You copied a blob of JSON from a log, an API response or a chat message, and you want it readable without opening a website or an editor. The classic answer is a one-line pipe. It works, but it has a sharp edge: if the clipboard isn't valid JSON, it can leave you with an empty clipboard.
Why the pipe works, and where it bites
pbpaste prints the clipboard, json_pp pretty-prints JSON from standard input, and pbcopy puts the output back on the clipboard. Your original text is overwritten once it runs.
Three things go wrong most often:
- Invalid JSON blanks the clipboard.
json_ppprints an error and no output, sopbcopyreceives nothing and sets the clipboard to empty. - You get one fixed result. No choice of indentation and no minify.
- Repairs aren't possible. Trailing commas, comments and single quotes are errors, not things the tool fixes.
If Terminal says json_pp: command not found, this method isn't available on your Mac; use one of the other methods below.
Method 1: pbpaste, json_pp and pbcopy
pbpaste | json_pp | pbcopyCopy your JSON, run the line, paste. It changes no settings, so there is nothing to undo except your original clipboard text, which is gone.
A safer shell function
This version only touches the clipboard when formatting succeeds. Add it to ~/.zshrc, then open a new Terminal window:
jpp() {
local out
out=$(pbpaste | json_pp) || { echo "Clipboard is not valid JSON" >&2; return 1; }
printf '%s\n' "$out" | pbcopy
}Copy JSON, type jpp, paste. To undo the setup, delete the function from ~/.zshrc and open a new window.
Method 2: one hotkey with Bytepliers
Bytepliers is our developer-utilities app. Its Detect & Replace Clipboard command works out what is on the clipboard, applies the single most useful transform and replaces the clipboard without opening a window.
- Open Bytepliers once and leave it running. The menu bar icon is on by default and the global hotkeys are registered at launch.
- Copy your JSON.
- Press ⌥⇧⌘B (Option-Shift-Command-B). Alternatives: Option-click the Bytepliers menu bar icon, or choose Tools > Detect & Replace Clipboard.
- Paste. A small HUD confirms the replacement. The HUD is on by default; the setting is Confirm clipboard replacements with a HUD in Settings > General.
- To undo, choose Tools > Restore Previous Clipboard, or the same item in the menu bar menu. It stays disabled until something has been replaced.
To change the hotkey, open Settings > Shortcuts and edit Detect & replace clipboard:. To have Bytepliers ready after a restart, turn on Launch at login and Start hidden in Settings > General.
If you always want formatting, use the Quick Panel and pick Format JSON explicitly. For a specific indent (2 spaces, 4 spaces or Tab), set it in the JSON Formatter tool in the main window.
Method 3: preview first with the Quick Panel
Press ⌥⌘B (Option-Command-B) from any app. The Quick Panel appears over your work, runs the best tool on the clipboard and shows the result. For JSON, auto-detect shows it pretty-printed.
- ⏎ copies the result and closes the panel.
- ⌘O opens it in Bytepliers.
- ⎋ closes the panel without copying anything.
- The Transform menu lets you choose Format JSON or Minify JSON instead of auto-detect.
The panel shows at most 20 KB or 400 lines of the result; ⏎ still copies everything. See Quick Panel, Instant Replace and the menu bar for the full key list.
Method 4: the bytepliers command in the pipe
Bytepliers also ships a command-line tool. Install it in Settings > Integrations > Command-Line Tool > Install…. Choose /usr/local/bin (asks for an administrator password if the folder isn't writable) or ~/.local/bin (no password, but the folder must be on your shell's PATH).
pbpaste | bytepliers json-format | pbcopyUse json-minify instead of json-format to minify. Add -n (--no-newline) to drop the trailing newline. Errors go to stderr as bytepliers: … with line:col: positions, which helps you find the broken spot.
A failed run can blank the clipboard just like json_pp. This version only copies on success:
out=$(pbpaste | bytepliers json-format) && printf '%s\n' "$out" | pbcopyThe tool works with the app closed, but it needs the access pass the app writes. If you see "Open Bytepliers once to enable the command-line tool.", open the app once. After the trial ends it also needs a license. Details are in the command-line docs. Transforms refuse input over 2 MB.
Which method to use
| Method | Terminal | Undo | Broken JSON | Preview |
|---|---|---|---|---|
pbpaste | json_pp | pbcopy | Yes | No | Errors; clipboard goes blank | No |
jpp function | Once, to set up | No | Errors; clipboard untouched | No |
| Detect & Replace (⌥⇧⌘B) | No | Restore Previous Clipboard | Not repaired | No |
| Quick Panel (⌥⌘B) | No | ⎋ copies nothing | Not repaired | Yes |
| JSON Formatter window | No | Edit the input | Repaired in Lenient mode | Yes |
If you format JSON now and then, the jpp function is enough and costs nothing. Bytepliers pays off if you do this many times a day, want undo, or want format and minify on one key. It is part of MacSuite ($349 one-time, as of November 2026; see pricing), and each app runs free for 7 days on each Mac.
When the JSON isn't valid
Detect & Replace and the Quick Panel's Format JSON use the strict JSON parser. Repaired JSON falls through, so they won't fix trailing commas, comments or single quotes.
To repair broken JSON, paste it into the JSON Formatter (⌘1). Its default Lenient mode repairs comments, trailing commas, single quotes, unquoted keys and True/False/None/undefined. It shows "Repaired N issues" and lists each fix by line and column. Copy the output, which is strict JSON. More in JSON Formatter in Bytepliers; the general Mac JSON guide covers Terminal-only options.
Fixes when it doesn't work
| Symptom | Cause | Fix |
|---|---|---|
| Hotkey does nothing | App not running, hotkey changed, or trial ended | Launch Bytepliers, check Settings > Shortcuts, enter a license |
| "Nothing to transform" / "No confident match" | Not strict JSON, or no confident match | Press ⇧⌘K to see what it detects, or use the JSON Formatter |
| "The clipboard is empty" | Nothing copied | Copy again, retry |
| Pretty JSON got squashed | Multi-line JSON is minified by design | Restore Previous Clipboard, or pick Format JSON in the Quick Panel |
| "too large for a quick transform" | Clipboard over 1,000,000 bytes | Open in the main window (⌘O); the JSON Formatter accepts up to 64 MB |
If your clipboard manager didn't record the result, that is intentional when the text looks like a key or token: Bytepliers marks the copy as concealed, and clipboard managers that honor that convention skip it.
Checklist before you try again
- Bytepliers is running (menu bar icon visible).
- The clipboard holds strict JSON, not a repaired-style variant.
- You are not expecting formatting from already-formatted multi-line JSON.
- The trial is active or a license is entered.
Format selected text in place
In any app, select the text and choose Services > Transform with Bytepliers from the app menu. It runs the same transform as Detect & Replace and replaces your selection without touching the clipboard. Selections over 2 MB are refused. There is no default shortcut; Settings > Shortcuts > Services > Keyboard Shortcuts… opens System Settings > Keyboard, where you can assign one.
If nothing works
Email support through our support page. Include the exact message shown, your macOS version, whether the clipboard text is strict JSON, and what you already tried.
Subject: Bytepliers Detect & Replace not formatting JSON
Bytepliers version: (Bytepliers > About)
macOS version:
Hotkey used: ⌥⇧⌘B (default / changed to: )
Message shown: (for example "No confident match")
Clipboard size: approx. KB
Tried: Quick Panel (⌥⌘B), ⇧⌘K, pasting into JSON FormatterCommon questions
Can I pretty print JSON on the clipboard without installing anything?
Yes. pbpaste | json_pp | pbcopy uses tools that ship with macOS, as long as json_pp exists on your Mac.
Why did my clipboard go empty?
The input wasn't valid JSON, json_pp printed an error and no output, and pbcopy then stored nothing. Use the jpp function above, which only copies on success.
Can I choose 4-space indentation from the hotkey?
No. Detect & Replace chooses the transform itself. Set the indent in the JSON Formatter tool in the main window.
Can I undo a replacement?
In Bytepliers, yes: Tools > Restore Previous Clipboard. With the plain pipe, no.