JSONプリティプリント
JSON Pretty Print formats JSON with indentation and line breaks so a human can read it. Paste a document below to do it here, or take the one line that does it in your own language — JavaScript, Python, Go, Java, C#, PHP, Ruby, Rust, jq or PowerShell — each with the default that catches people out, because every one of these APIs has one.
このツールの画面は英語表記です。
Built in. No dependency, in the browser and in Node.
以下の解説は英語のみでご覧いただけます。
How does JSON Pretty Print work?
Pretty-printing JSON means one thing: parse the document, then write it back out with a newline after every comma and a level of indentation per level of nesting. The bytes are equivalent — a parser cannot tell the two apart — but one of them is readable and the other is a wall.
Two different questions, one page
People searching for this want one of two things. Either a box to paste a payload into, which is the panel above; or the line of code that does it inside a program they are writing, which is the picker below it. This page answers both, because being sent to a formatting widget when you needed json.dumps(obj, indent=2) is a waste of a click.
Every language has a default that surprises somebody
This is the part worth knowing, and it is why the recipes here carry a note each rather than being a list of one-liners. Python escapes every non-ASCII character unless you pass ensure_ascii=False, so café arrives as caf\u00e9. Go escapes <, > and & because the output might once have gone into a <script> tag. PHP escapes forward slashes, so every URL in your output looks broken. PowerShell's ConvertTo-Json truncates anything nested more than two levels deep and does not warn you — it just replaces the rest with a type name and carries on.
And in JavaScript, the mistake is in the call itself: JSON.stringify(value, 2) looks right, compiles, runs, and returns the minified string, because the second argument is the replacer function and the third is the indent.
Sorting keys is a separate decision
Alphabetising keys makes two versions of the same document diffable, which is the whole reason to do it — without it, a serialiser that emits keys in insertion order produces a diff full of moves. It is off by default here because it changes the document's order, and for a config file or a lockfile that order sometimes carries meaning.
Indentation, and what to pick
Two spaces is the web and JavaScript convention and keeps deeply nested documents on screen. Four is the norm in Python and much of the backend world. Tabs let each reader choose their own width, which is the strongest argument for them and the reason some projects insist on it. None of the three is more correct than the others; the only wrong answer is mixing them within one file.
This does not change what the data means
Whitespace between tokens is not significant in JSON, so pretty-printing is reversible and lossless — run the output through a minifier and you get the input back, byte for byte, unless you also sorted the keys. What it does change is size: indentation can add 20–40% to a document, which matters on the wire and does not matter at all in a log you are reading.
If the document does not parse, nothing here can format it, and the error below names the line and column. JSON Validator will also offer to repair the usual causes — a trailing comma, a single quote, an unquoted key.
Nothing is uploaded
The parse and the re-serialise both happen in this tab, in JavaScript that is already loaded. The payloads people pretty-print are API responses and log lines, which routinely contain tokens and customer records, and the page's Content-Security-Policy sets connect-src 'self' — so the browser would block an upload rather than merely not attempting one.
Minified
{"id":42,"tags":["prod","payment"],"ok":true}Pretty-printed
{
"id": 42,
"tags": [
"prod",
"payment"
],
"ok": true
}What options and edge cases does JSON Pretty Print support?
| Parameter | Type | Default | Behaviour & edge cases |
|---|---|---|---|
| JavaScript | JSON.stringify | built in | JSON.stringify(value, null, 2). The second argument is the replacer — passing 2 there does nothing at all. |
| Python | json.dumps | stdlib | json.dumps(obj, indent=2). Add ensure_ascii=False or every non-ASCII character is escaped. |
| jq | shell | — | jq . file.json, and jq -S . to sort keys. Before jq 1.7, large integers were silently altered. |
| Command line | python3 -m json.tool | — | Present on almost every machine, with --indent, --sort-keys and --no-ensure-ascii. |
| Go | encoding/json | stdlib | json.MarshalIndent for a value, json.Indent for bytes you already have. Both escape angle brackets. |
| Java | Jackson | — | writerWithDefaultPrettyPrinter(). Its default prints arrays on one line until you set an array indenter. |
| C# | System.Text.Json | .NET Core 3+ | JsonSerializerOptions { WriteIndented = true }. Escapes far more than the specification requires. |
| PHP | json_encode | built in | JSON_PRETTY_PRINT, plus JSON_UNESCAPED_SLASHES and JSON_UNESCAPED_UNICODE, which you almost always want. |
| Ruby | JSON.pretty_generate | stdlib | Not the same as to_json, which stays compact. |
| Rust | serde_json | — | to_string_pretty. Value sorts keys unless the preserve_order feature is enabled. |
| PowerShell | ConvertTo-Json | built in | Defaults to -Depth 2 and silently truncates below it. Always pass -Depth explicitly. |
Frequently asked questions
How do I pretty print JSON in JavaScript?
JSON.stringify(value, null, 2). The three arguments are the value, a replacer, and the indent — so the mistake everyone makes once is JSON.stringify(value, 2), which puts 2 in the replacer slot, does nothing, and returns the minified string. Pass "\t" instead of 2 for tabs. Be aware of what stringify quietly discards along the way: undefined values and functions vanish from objects and become null inside arrays, a Map or Set becomes {}, and a BigInt throws.
How do I pretty print JSON in Python?
json.dumps(obj, indent=2). The default that catches people is ensure_ascii=True, which escapes every non-ASCII character — "café" comes out as "caf\u00e9", valid and unreadable. Pass ensure_ascii=False to keep UTF-8, and open any output file with encoding="utf-8" when you do. sort_keys=True alphabetises, which is what makes two dumps diffable.
How do I pretty print JSON from the command line?
jq . file.json if jq is installed; python3 -m json.tool file.json if it is not, which covers almost every machine with Python on it. jq adds sorting with -S, a configurable indent with --indent, and compaction with -c. One caution: up to jq 1.6, numbers were parsed as doubles, so a 64-bit ID could come back silently changed — jq 1.7 preserves unmodified number literals, so check the version before piping identifiers through it.
Is pretty-printed JSON still valid JSON?
Yes. Whitespace between tokens carries no meaning in JSON, so an indented document and a minified one parse to exactly the same value — RFC 8259 allows space, tab, newline and carriage return anywhere between structural tokens. The only difference is size: indentation typically adds 20–40%, which is worth removing before sending a payload over the wire and worth keeping in anything a person reads.
What is the difference between pretty print, format and beautify?
Nothing, as verbs — they all mean adding whitespace so the structure is visible. The three pages here differ in what else they do. This one pairs the formatter with the code to do it in each language. JSON Formatter has the full option set: JSONC comment stripping, key sorting, Unicode escaping. JSON Beautifier is aimed at the specific job of turning a minified blob back into something readable. Pick whichever matches what you came for.
Why does my pretty-printed output have \u escapes in it?
Because the serialiser escaped non-ASCII characters, and several do it by default. Python's json.dumps has ensure_ascii=True; C#'s System.Text.Json escapes anything its HTML-safe encoder dislikes; PHP escapes non-ASCII unless told otherwise. All of it is valid JSON and none of it is readable. The fix is one argument in each case — ensure_ascii=False, UnsafeRelaxedJsonEscaping, JSON_UNESCAPED_UNICODE — and the picker above shows it for whichever language you are in.
Is my JSON uploaded to a server?
No. Parsing and re-serialising happen in this tab, in JavaScript already loaded on the page, and there is no endpoint on the other end to send anything to. That matters here more than it might sound: the documents people pretty-print are API responses and log lines, which routinely carry tokens, session identifiers and customer records. The page is served with connect-src 'self', so the browser itself blocks any request to another origin.