About the JSON formatter
A JSON formatter turns compact or messy JSON into an indented, readable layout. API responses, log lines and config exports often arrive as one long line, which makes nested objects and arrays hard to follow. Formatting puts each key on its own line and indents every level, so the structure is clear at a glance.
This formatter also checks your JSON while you type. If something is wrong, the line and column of the problem appear above the editor, so you can fix it before formatting.
How to use the JSON formatter
- Paste your JSON into the Input editor, or click Load sample to try it with example data.
- Choose an indentation style: 2 spaces, 4 spaces or tabs.
- Tick Sort object keys alphabetically if you want keys in a predictable order, which makes two JSON documents easier to compare.
- Click Format JSON or press Ctrl + Enter (Cmd + Enter on Mac), then use Copy result.
Examples
Pretty print a minified API response
Input
{"id":7,"user":{"name":"Ada","roles":["admin","dev"]},"active":true}Output
{
"id": 7,
"user": {
"name": "Ada",
"roles": [
"admin",
"dev"
]
},
"active": true
}2-space indentation. Nested objects and arrays each get their own level.
Sort keys so two documents line up
Input
{"zip":"10115","city":"Berlin","country":"DE"}Output
{
"city": "Berlin",
"country": "DE",
"zip": "10115"
}With Sort object keys alphabetically ticked.
Common errors and how to fix them
Expected double-quoted property name in JSON at position 26 (line 1 column 27)
There is a trailing comma before the closing } or ]. JSON does not allow it, unlike JavaScript. Delete the last comma.
Expected property name or '}' in JSON at position 1 (line 1 column 2)
A key is not wrapped in double quotes, as in {name: "Ada"}. Every JSON key needs double quotes: {"name": "Ada"}.
Unexpected token ''', "{"name": 'Ada'}" is not valid JSON
A string uses single quotes. JSON only accepts double quotes, so change 'Ada' to "Ada".
Good to know
- Input must be valid JSON. Comments, trailing commas, single-quoted strings and unquoted keys are not part of the JSON standard and are reported as errors.
- Sorting keys reorders object keys at every level, but never changes the order of items inside arrays.
- Numbers are read as JavaScript numbers, so integers larger than 2^53 (about 9 quadrillion) can lose precision.
- Pressing Tab in the editor inserts indentation. Press Escape, then Tab, to move focus out of the editor.
Frequently asked questions
What is the difference between formatting and validating JSON?
Validating only checks whether the JSON is correct. Formatting validates it first and then rewrites it with indentation, so you get both a correctness check and a readable result.
Should I use 2 spaces, 4 spaces or tabs?
2 spaces is the most common choice for JSON and keeps deeply nested data compact. 4 spaces is easier to scan for some people, and tabs let each editor choose the width. Pick whatever your project already uses.
Why does my JSON show an error at a line that looks fine?
The parser reports where it noticed the problem, which can be just after the real mistake. Check the end of the previous line for a missing comma, an extra trailing comma or an unclosed quote.