JSON Formatter / Beautifier
Pretty-print JSON with configurable indentation.
Overview
The JSON formatter pretty-prints a JSON document with consistent indentation, sorted or preserved key order, and your choice of two-space, four-space, or tab indent. Paste a minified API response and immediately get a human-readable version, or take a hand-edited blob and clean up its inconsistent spacing.
It's the most-reached-for action in any developer's toolbox: every time you debug an API call, inspect a config file, or write a fixture by hand. Engineers reach for a json beautifier when they want the document to be skimmable in a code review or paste-friendly in a chat message.
How it works
The formatter parses the input into an in-memory tree, then re-serialises it with the chosen indentation. Parsing follows the JSON specification in ECMA-404 / RFC 8259 — strict mode rejects trailing commas, unquoted keys, and comments. For looser input, the JSON5 decoder handles those extensions first and feeds strict JSON into the formatter.
Key ordering preserves source order by default, which matters for documents where humans have arranged keys deliberately (config files, OpenAPI specs). Alphabetical sorting is opt-in and is recursive: every object at every depth gets the same treatment. Number formatting preserves the source representation rather than re-parsing through a double — so 1.0 stays 1.0 instead of becoming 1.
Examples
Input: {"name":"Alice","age":30,"tags":["admin","ops"]}
Output (2-space):
{
"name": "Alice",
"age": 30,
"tags": [
"admin",
"ops"
]
}
Input: {"b":2,"a":1,"c":{"y":2,"x":1}}
Output with sort keys:
{
"a": 1,
"b": 2,
"c": { "x": 1, "y": 2 }
}
FAQ
What happens if the JSON is invalid?
The formatter reports the exact line and column of the first syntax error so you can fix it. For a more detailed validator with structured error output, use the JSON validator.
Does it preserve floating-point precision?
Yes — numbers are kept as their literal source text rather than round-tripped through a double. That avoids 9.99 accidentally becoming 9.9900000000000002.
Can I get a compact one-line version instead?
For minified output, use the JSON minifier. The formatter is for pretty-printing; minifying is a separate operation.