JSON Formatter
About the JSON Formatter
This JSON formatter and validator pretty-prints, minifies and sorts JSON as you type, and pinpoints the exact line and column of any syntax error. Paste an API response or config file and get readable, valid JSON back in one step, without sending your data anywhere.
What makes JSON valid?
JSON (RFC 8259) is stricter than JavaScript object syntax. Keys must be double-quoted strings, strings must use double quotes, and the only literals allowed are true, false and null.
The most common mistakes are a trailing comma ({"a": 1,}), single quotes ({'a': 1}), unquoted keys ({a: 1}) and comments. JSON has no comment syntax, so // note or /* note */ will always fail. This tool uses the browser's strict parser, so anything it accepts will also parse in other standard JSON libraries.
Beautify vs minify
Beautified JSON puts each key on its own line with consistent indentation, which makes nested data easy to scan and gives clean line-by-line diffs in Git. Two spaces is the most common style; four spaces and tabs are also popular.
Minified JSON removes every optional space and newline. {"name": "Ada", "age": 36} becomes {"name":"Ada","age":36}. Use it for request bodies, environment variables or anywhere size matters. The output panel shows the byte size next to the input size so you can see the saving.
Why large numbers can change
JavaScript stores numbers as 64-bit floats, which represent integers exactly only up to 2^53 - 1 (9007199254740991). A 64-bit ID like 12345678901234567890 would normally be rounded to 12345678901234567000 when parsed.
Where the browser supports JSON.rawJSON (recent Chrome, Edge and Firefox), this formatter keeps such integers exactly as written. In older browsers it shows a warning instead of silently changing your data.
How to Use the JSON Formatter
- Paste or type JSON into the Input box, or click Load example. The output updates as you type, so there is no Run button.
- Choose an Indent of 2 spaces, 4 spaces or Tab, turn on Sort keys if you want keys in alphabetical order, and pick Beautify or Minify. If the input is invalid, the error banner names the line and column where parsing stopped.
- Click Copy to put the result on your clipboard or Download to save it as formatted.json. Click Clear to start over.
JSON Formatter Examples
Beautify a one-line API response
Indent set to 2 spaces, Beautify, Sort keys off.
Input:
{"id":101,"user":{"name":"Ada","roles":["admin","editor"]},"active":true}
Output:
{
"id": 101,
"user": {
"name": "Ada",
"roles": [
"admin",
"editor"
]
},
"active": true
}
Minify with sorted keys
Minify and Sort keys on: keys are ordered alphabetically at every level, then all whitespace is removed.
Input:
{
"name": "Ada",
"age": 36,
"address": {"zip": "N1", "city": "London"},
"id": 1
}
Output:
{"address":{"city":"London","zip":"N1"},"age":36,"id":1,"name":"Ada"}
Sort keys leaves array order alone
Beautify with Sort keys on: the keys a and c move, but the array [3,1] keeps its order.
Input:
{"b":1,"a":{"d":[3,1],"c":2}}
Output:
{
"a": {
"c": 2,
"d": [
3,
1
]
},
"b": 1
}
Common Errors
- Invalid JSON after a trailing comma, as in {"a": 1,} or [1, 2,].
- Delete the comma after the last property or item. Standard JSON does not allow it.
- Invalid JSON at column 2 for {'a': 1}.
- Replace single quotes with double quotes. JSON strings and keys must use ".
- Invalid JSON at column 2 for {a: 1}.
- Put double quotes around every key: {"a": 1}.
- Invalid JSON where a // or /* */ comment starts.
- JSON has no comment syntax. Remove the comments before pasting, or keep the notes in a separate field such as "_comment".
Frequently Asked Questions
- Is my JSON uploaded to a server?
- No. Parsing and formatting run in your browser with the built-in JSON object. The data never leaves your device, so it is safe to paste tokens or internal payloads.
- Why does my JSON say "Unexpected token"?
- The parser hit a character that is not allowed at that point. Check the reported line and column for a trailing comma, a single-quoted string, an unquoted key or a comment.
- Does the formatter accept JSON5 or comments?
- No. It validates against standard JSON, so comments, trailing commas and single quotes are reported as errors. Remove them to get JSON that every parser accepts.
- Does Sort keys change my arrays?
- No. Only object keys are sorted. Array items keep their original order because order is meaningful in arrays.
- What is the difference between a JSON formatter and a JSON validator?
- A validator only tells you whether the text is valid JSON; a formatter also rewrites it. This tool does both at once: every keystroke is validated, and valid input is formatted immediately.