Raw JSON is hard to read. This guide shows you how to format JSON for readability — using code, command-line tools, and our free online formatter.
JSON formatting is the process of adding whitespace — indentation, line breaks, and spacing — to JSON data so humans can read it. The underlying data does not change. Only the presentation changes.
{"users":[{"id":1,"name":"Alice","roles":["admin"]},{"id":2,"name":"Bob","roles":["viewer"]}],"settings":{"theme":"dark","notifications":true}}{
"users": [
{
"id": 1,
"name": "Alice",
"roles": ["admin"]
},
{
"id": 2,
"name": "Bob",
"roles": ["viewer"]
}
],
"settings": {
"theme": "dark",
"notifications": true
}
}Nested objects and arrays are impossible to scan in a single line. Proper indentation reveals the structure instantly.
When an API returns malformed JSON, formatting it is the first step to finding the error.
Formatted JSON produces meaningful diffs. Minified JSON shows the entire line changed for a single character edit.
const obj = { name: "Alice", age: 30 };
// Format with 2-space indentation
const formatted = JSON.stringify(obj, null, 2);
console.log(formatted);
// Output:
// {
// "name": "Alice",
// "age": 30
// }import json
data = {"name": "Alice", "age": 30}
# Format with 2-space indentation
formatted = json.dumps(data, indent=2)
print(formatted)# Format a JSON file
jq . data.json > formatted.json
# Format from stdin
cat data.json | jq .
# Format with 4-space indentation
jq --indent 4 . data.jsonJSON does not allow trailing commas. Remove the comma after the last key-value pair.
JSON requires double quotes for strings and keys. Single quotes are invalid.
All object keys must be wrapped in double quotes. Unquoted keys are JavaScript-only.
Standard JSON does not support comments. Remove all // and /* */ comments.
If you do not want to write code or install tools, use our free JSON formatter. It runs entirely in your browser — no data is uploaded.
Copy your raw JSON from an API response, log file, or database export.
Go to JSON Formatter Online and paste it into the input box.
Click the Format button.
Copy the formatted result or download it as a .json file.
Two spaces is the most common convention, but four spaces and tabs are also valid. The key is consistency within your project.
No. Formatting only changes whitespace — indentation, line breaks, and spacing. The actual data structure and values remain identical.
Yes. Use built-in tools like JSON.stringify() in JavaScript, json.dumps() in Python, or jq on the command line.
Different formatters use different indentation defaults (2 vs 4 spaces), key sorting rules, and line wrapping. Most tools let you configure these.
Commit formatted JSON for readability during code review. Use minified JSON only for production builds or API responses where size matters.
Paste your raw JSON into our free formatter. Get perfectly indented output in one click.
Try JSON Formatter Online →