How to Format JSON on Mac

Pretty-print messy or minified JSON on Mac without pasting it into a website. Use the Format JSON extension for Raycast, or jq and Python in Terminal.

UPDATED

You copied a response from an API or a log line, and it's one long line of brackets and quotes. You need to read it, and you'd rather not paste it into a random website.

The short answer: install the free Format JSON extension for Raycast, copy the JSON and run Format Clipboard JSON. Paste, and it's indented. Without installing anything, run pbpaste | python3 -m json.tool in Terminal.

MethodWorks fromHandles escaped JSONStays on your Mac
Format JSON for RaycastClipboard, editor selectionYesYes
python3 -m json.toolTerminalNoYes
jqTerminalWith fromjsonYes
Online formattersBrowserSomeNo

Format JSON with Raycast

Format JSON: pretty-print JSON from anywhereInstall

Format JSON works on what you've already got: the JSON on your clipboard, or the JSON selected in your editor. It also accepts JavaScript objects with unquoted keys, and it parses stringified JSON before formatting it.

Copy the JSON, open Raycast and run Format Clipboard JSON. The formatted version replaces what's on your clipboard, ready to paste.

Format Selected JSON and Show opens the formatted JSON in a viewer.
Format Selected JSON and Show opens the formatted JSON in a viewer.
Pro tip: give Format Clipboard JSON a hotkey and turn on Auto Paste in the extension's preferences. Then select messy JSON in any editor, copy, press the hotkey, and it's replaced with the formatted version.

All the commands:

  • Format Clipboard JSON: formats your clipboard and copies (or pastes) the result.
  • Format Selected JSON: formats the JSON selected in the frontmost app and replaces it.
  • Format Selected JSON and Show: formats the selection and opens it in a viewer, for when you just want to read it.
  • Format JSON: paste JSON into a text field and format it there.
  • Format Array of JSON to JSONLines: turns an array of objects into JSON Lines, one object per line.
  • Format Text into Valid JSON Value: wraps text in double quotes and escapes it, so you can drop it into a JSON file.

In the preferences, choose the Indentation: a tab, or 2, 4 or 8 spaces.

Format JSON works on Windows too.

Use Terminal

macOS can format JSON in Terminal without anything extra.

With Python, which comes with the Xcode Command Line Tools:

pbpaste | python3 -m json.tool

Add | pbcopy to the end to put the result back on your clipboard. Use --indent 2 for two spaces instead of four.

With jq, which ships with recent versions of macOS and is also on Homebrew:

pbpaste | jq .

jq can do much more than format. jq -c '.[]' turns an array into JSON Lines, and jq '.items[0].name' pulls out a single value.

Why not an online formatter?

Online JSON formatters work, but they send your text to someone else's server. API responses often contain tokens, email addresses or customer data. Formatting locally, in Raycast or in Terminal, keeps it on your Mac.

New to Raycast?

Here's a quick tour of what else it can do, in under seven minutes:

Frequently Asked Questions

How do I pretty-print JSON on Mac without installing anything?

Copy the JSON and run pbpaste | python3 -m json.tool in Terminal. On recent versions of macOS, jq is also built in: pbpaste | jq .

Is it safe to paste JSON into an online formatter?

Not if it contains tokens, customer data or anything private. The text is sent to someone else's server. Formatting locally, in Raycast or Terminal, keeps it on your Mac.

How do I format stringified or escaped JSON?

Format JSON for Raycast detects stringified JSON, like an object stored inside a string with escaped quotes, parses it and formats the result.

How do I convert a JSON array to JSON Lines?

Run Format Array of JSON to JSONLines in Raycast and paste the array. In Terminal, jq -c '.[]' does the same.

Format JSON from your clipboard with one hotkey. Try Raycast with the free Format JSON extension.

Download