How to use the JSON beautifier
This JSON formatter online works entirely in the page: nothing is uploaded, and the result updates as you type or edit the input.
- Paste JSON into the left box, drop a
.jsonfile on it, or use Open file. The file is read by your browser and is never uploaded. - Choose Beautify for pretty JSON or Minify to strip whitespace for a smaller payload.
- Pick 2 spaces, 4 spaces or tabs, and tick Sort keys if you want object keys in alphabetical order (handy before comparing two documents).
- Copy or download the result. If there is an error, press Go to error to jump to the problem character.
JSON pretty print, without changing your data
A formatter that simply runs your text through JSON.parse and back will quietly round large integers (anything above 253, such as 64-bit IDs) and rewrites numbers like 1.50 as 1.5. This beautifier uses its own JSON parser, which keeps every number and string exactly as you wrote it and only changes the whitespace between tokens, so the output holds exactly the same data. Duplicate keys are kept too, and flagged, because most parsers silently keep only the last one.
Before and after, using 2-space indentation:
{"id":7,"tags":["a","b"],"owner":{"name":"Sam"}}{
"id": 7,
"tags": [
"a",
"b"
],
"owner": {
"name": "Sam"
}
}JSON formatter and validator in one
Formatting only works on valid JSON, so the formatter validates first against the grammar in RFC 8259. The rules people trip over most are:
- Keys and strings need double quotes; single quotes are not JSON.
- No comma after the last item in an object or array.
- No comments, and no
undefined,NaNorInfinity. - Numbers cannot have leading zeros (
007) or a leading+. - Line breaks and tabs inside strings must be escaped as
\nand\t.
For a fuller error report with hints for each of these, use the JSON validator. To explore a big document instead of reading it top to bottom, open it in the JSON viewer.
Format JSON in code
When you need clean JSON inside a script or pipeline rather than in a browser, every major language has a one-liner:
// JavaScript / Node.js
JSON.stringify(data, null, 2)
# Python
python -m json.tool input.json
# Command line with jq
jq . input.jsonTwo spaces is the most common indent in JavaScript projects, four in Python. Neither is more correct: whitespace between tokens has no meaning in JSON, so pick whatever your team's formatter uses.