What is a JSON formatter?
A JSON formatter (also called a JSON beautifier or pretty-printer) takes JSON text and prints it again with one value per line and consistent indentation, so the nesting of objects and arrays is visible at a glance. The data does not change: whitespace between tokens is insignificant in JSON, as defined by RFC 8259 and ECMA-404. What changes is how quickly a person can find the field they are looking for in an API response, a log line or a configuration file.
How to pretty-print JSON
- Paste the JSON into the input editor, drop a
.jsonfile onto it, or click Open file. - Choose the indentation: 2 spaces, 4 spaces or a tab. Tick Sort keys to order the keys of every object alphabetically.
- Click Format (or press Ctrl/β + Enter). The formatted JSON appears on the right, ready to copy or download.
Example
This minified response from an API:
{"id":42,"user":{"name":"Ana","roles":["admin","dev"]},"active":true,"balance":12345678901234567890}
becomes, with 2-space indentation:
{
"id": 42,
"user": {
"name": "Ana",
"roles": [
"admin",
"dev"
]
},
"active": true,
"balance": 12345678901234567890
}
Note the last value. In a formatter based on JSON.parse and JSON.stringify it would come out as 12345678901234567000, because JavaScript numbers hold only about 15β17 significant digits. IDs, account balances in the smallest unit and blockchain amounts often exceed that. Here the number text is copied through untouched.
What happens when the JSON is invalid
The formatter validates as you type. If the text is not valid JSON, the status line turns red and the problems list shows each error with its line and column; click an entry to jump to it. Typical problems are a trailing comma after the last item, a missing comma between two properties, single quotes, unquoted keys, comments, and brackets that do not balance. Click Fix JSON to repair them automatically and format the result in one step, or see the JSON validator page for how each error is detected.
Formatting options explained
- Indent: the string placed before each nested level. It affects only readability and file size.
- Sort keys: orders the keys inside every object by Unicode code point, recursively. Helpful before committing generated files or before a JSON diff, so that two files with the same data line up.
- Minify: the reverse of formatting. Removes all optional whitespace; see the JSON minifier.
- To YAML: converts the same data to YAML; see JSON to YAML.