Online JSON Formatter
Paste messy or minified JSON and get clean, consistently indented JSON back as you type. The JSON formatter checks the syntax at the same time, so you know the result is valid, and points to the exact line of any error. Choose the indentation, preview the output, and copy or download it.
How to format JSON online
- Paste your JSON into the left editor. You can also open a .json or .txt file with Open file (Ctrl+O) or drop a file onto the page.
- The formatted JSON appears on the right in the Preview view as you type. With Live turned off, press Format or Ctrl+Enter.
- Use the Indent selector to set how many spaces each level is indented. Two is the usual choice.
- Press Copy or Download, or switch the output to the Code or Tree view to keep working on it.
What a JSON formatter does
JSON from an API, a log file or a database is usually minified: one long line with no spaces. That is efficient for computers but almost impossible for people to read. A JSON formatter, also called a JSON pretty printer, parses the text and writes it back out with one key per line and each level of nesting indented, so you can see the structure at a glance.
Formatting only touches the whitespace between values. Keys keep their order, strings keep their exact content, and numbers are written the way they were. The formatted JSON is the same data as the original, just easier to read, review and diff.
Because the formatter has to parse the JSON first, it is also a quick validity check. If the input is broken, you get the line and column of the first error rather than a silently wrong result.
Before and after
This minified response:
{"id":1042,"status":"shipped","items":[{"sku":"A-1","qty":2},{"sku":"B-7","qty":1}],"paid":true}
becomes:
{
"id": 1042,
"status": "shipped",
"items": [
{ "sku": "A-1", "qty": 2 },
{ "sku": "B-7", "qty": 1 }
],
"paid": true
}
Choosing an indentation style
- 2 spaces is the default for most JavaScript and TypeScript projects, npm's package.json and many style guides. It keeps deeply nested data from drifting off the right edge of the screen.
- 4 spaces is common in Python, Java and C# projects and is easier to scan for some people.
- 0 removes all indentation and line breaks, which is the same as pressing Compact. For a dedicated tool with size savings, use the JSON Minifier.
Pick whichever matches the files in your project. Parsers ignore indentation completely, so it is purely a readability choice.
Format JSON in your own tools
When you are not in a browser, these do the same job:
- JavaScript and Node.js:
JSON.stringify(data, null, 2) - Python:
json.dumps(data, indent=2), orpython -m json.tool file.jsonon the command line - jq:
jq . file.json - PHP:
json_encode($data, JSON_PRETTY_PRINT) - VS Code: open the file and press Shift+Alt+F (Shift+Option+F on a Mac)
The online formatter is quicker when the JSON is already on your clipboard, when you want to see it as a tree, or when you are on a computer where you cannot install anything.
When formatting fails
If the formatter reports an error, the input is not valid JSON. The usual suspects are a comma after the last item, single quotes instead of double quotes, keys without quotes, and comments. The JSON Validator explains each error in more detail, and JSON Repair fixes most of them automatically. If the input is a JSON value that was turned into a string, with backslashes before every quote, use the JSON Parser to decode it first.
More than a formatter
- Tree view for browsing and editing nested data. See the JSON Viewer for tips.
- Sort and transform in each editor's ⋯ menu to order keys or filter a large response.
- Save to keep your work in this browser, and Share to send a link.
- Fonts, sizes and colour themes in the settings dialog, plus a dark mode for late nights.
Free and private
The JSON formatter is free, needs no account and has no usage limits. Formatting happens in your browser, so your data is never uploaded, and the tool keeps working with files of several megabytes because there is no server round trip.