How to use the JSON formatter
- Paste your data into the JSON box (a sample is filled in).
- Choose an Indent: 2 spaces, 4 spaces, Tabs, or None (minified).
- Tick Sort keys A–Z if you want object keys in alphabetical order.
- Read the Formatted JSON, with its line count and size, or the error message and code frame.
- Copy the result or download it as
formatted.json.
What it does and when to use it
JSON from an API, a log file or a database export usually arrives as one long line. The formatter breaks it into an indented tree so you can see which values belong to which object and how deep the nesting goes. Sorting keys is useful before comparing two versions of a config file, because the same data in a different order then lines up.
It also acts as a quick checker. Invalid JSON is not “fixed” behind your back: the tool stops at the first problem and tells you where it is, with a marker under the exact character.
To compare two JSON documents, use the JSON diff tool. If you need types for code, the JSON to TypeScript converter turns the same data into interfaces, and for broken JSON with comments or single quotes, the JSON repair tool can try to fix it.
How it works
The input is parsed with the browser’s built-in JSON.parse. If that succeeds, the tool optionally sorts keys recursively and prints the result with your chosen indent. If parsing fails, a strict scanner written for this site walks the text according to the JSON standard (RFC 8259) to find the first error and explain it in plain words, such as “Trailing comma” or “Missing comma between properties”. A byte-order mark at the start of a file is ignored. Everything happens on your device.
Worked examples
These outputs come from the formatter.
A compact object. {"a":1,"b":[1,2]} with a 2-space indent becomes:
{
"a": 1,
"b": [
1,
2
]
}
Sorted keys. {"b":2,"a":{"d":4,"c":3}} with Sort keys A–Z ticked puts a before b, and inside a, c before d.
Single quotes. {'name': 'Asha'} is not JSON. The tool reports: “Invalid JSON — line 1, column 2: Object keys must use double quotes, not single quotes.”
Limits and tips
- Duplicate keys are kept only once (the last value wins), as in most JSON parsers. The validator lists them.
- Comments are not allowed in standard JSON. Remove them, or use the repair tool.
- Very large files of many megabytes may make the page slow, since everything runs in the browser tab.
- Escaped Unicode such as
éis printed as the character itself (é) after formatting, which is the same value.
Frequently asked questions
Why does my JSON fail to format?
Does sorting keys change my data?
Can I minify JSON here too?
Will large numbers stay exact?
Is my JSON uploaded?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.