What is a JSON formatter?
JSON (JavaScript Object Notation) is the data format the modern web runs on: APIs return it, configuration files are written in it, logs are emitted as it. But JSON that comes out of a machine is usually optimised for machines — a single line with no spaces, thousands of characters long. A JSON formatter takes that dense string and rewrites it with line breaks and indentation so a human can actually read the structure: nested objects open and close on their own lines, arrays list one element per line, and the shape of the data becomes visible at a glance.
A formatter that also validates — like this one — does something just as important before it formats: it checks that the document is really JSON. Most "formatting" failures are not formatting problems at all; the input is broken JSON, and a good tool tells you exactly where, instead of showing a blank page or a vague "invalid input" complaint.
How to use this tool
- Paste your JSON into the box above (or press Load sample to see a worked example). You can also upload a .json file or drop one onto the box — the file is read in your browser and never sent anywhere.
- Choose an indentation style — 2 spaces is the community default; 3 spaces, 4 spaces and tabs are one click away — and tick Sort keys if you want object members alphabetised, which is handy when diffing two payloads.
- Press Format. If the JSON is valid you get the formatted document, some quick statistics, a collapsible tree view and a graph view for exploring deep structures. If it is not valid, you get the precise line and column of the first error, with the offending line quoted.
- Tick Auto-format as I type if you would rather not press the button at all: the result updates as you edit (very large inputs are still formatted on demand, to keep typing smooth).
- Use Minify when you need the opposite direction — one compact line for embedding in a request or a config value — then Copy result, Download result or Print result to take the output with you.
Repairing broken JSON — with the receipts
Sometimes you do not get to choose your input: a hand-edited config
with single quotes and a trailing comma, a truncated log line, a
snippet copied out of Python with True and
None in it. Repair broken JSON runs a
tolerant repair pass (the open-source jsonrepair
library) over text like that and produces the closest valid JSON.
Repairs here are never silent, because a repair is a guess about what you meant. Your original text is left untouched; the repaired document appears as the result, under a banner that says it was repaired and lists what the repair changed — comments removed, quotes added, trailing commas dropped, brackets closed — plus a line-by-line difference count so you can judge how far the guess went. Only if you press Replace my input does the repaired version become your input. If a repair would have to invent data rather than fix syntax, the tool refuses and changes nothing.
Tree view and graph view
The tree view renders the document as collapsible branches — good for reading deep nesting in order, and for spotting the one field that is the wrong type. String values that are image URLs get a dotted underline; hovering one previews the image (the image is fetched only at that moment, directly from its own host). The graph view draws the same structure as a node-and-line diagram you can pan and zoom, with branches you can collapse and expand — better than the tree when you want the shape of the whole document at once. To keep your browser responsive, the graph draws at most 400 nodes; when a document is larger, the graph is partial and says so, with the full node count shown.
How JSON validation works
Validation is parsing: the tool feeds your text to a strict JSON parser
that follows the grammar defined by RFC 8259 and ECMA-404. The grammar
is small and unforgiving. A JSON value is an object, array, string,
number, or one of the three literals true,
false, null. Strings must be double-quoted.
Object keys must be strings. Numbers may not have leading zeros or a
bare decimal point. There are no comments, no single quotes, no trailing
commas, and no unquoted keys — most of the "JSON" people write by hand
breaks at least one of these rules, because it looks so much like
JavaScript object syntax while being considerably stricter.
When parsing fails, the parser stops at the first character it cannot accept. This tool reports that position as a line and column and shows you the line, because the first error is the only one worth fixing: everything after it is usually a cascade. Fix the first error, format again, and repeat — real-world payloads typically surrender after two or three rounds.
Examples
This compact payload:
{"user":{"id":42,"name":"Ada"},"roles":["admin","editor"],"login_count":318} formats into:
{
"user": {
"id": 42,
"name": "Ada"
},
"roles": [
"admin",
"editor"
],
"login_count": 318
} And this broken input — note the missing quote and the trailing comma — is reported as an error at the exact line and column where parsing stops, instead of being silently "repaired" into something you did not write:
{
"name": "Ada,
"roles": ["admin",]
} Common JSON mistakes
- Trailing commas after the last member of an object or array — legal in JavaScript, illegal in JSON.
- Single quotes around strings or keys — JSON requires double quotes, always.
- Comments copied in from a config file — JSON has none (the variant that allows them is JSONC/JSON5).
- Unescaped control characters — a literal newline or tab inside a string must be written as
\nor\t. - NaN and Infinity — JavaScript will happily print them; JSON forbids both. Serialisers that emit them produce documents no strict parser accepts.
- Leading zeros like
007— invalid as a number; quote it if it is an identifier, not a quantity.
If you are deciding which format a file should be in at all, read our comparison of JSON vs YAML — the two formats look interchangeable from a distance and behave very differently up close.