Unformatted JSON is a nightmare to debug. A single long line of JSON with hundreds of fields is nearly impossible to read. Formatting (also called "pretty printing") adds indentation and line breaks to make the structure immediately visible.
Method 1: Use an Online JSON Formatter
The fastest way. Just paste your JSON into an online formatter, click format, and get back beautified JSON. Our JSON formatter also validates your JSON and highlights any syntax errors.
Method 2: Using JavaScript
const data = {"name":"John","age":30};
console.log(JSON.stringify(data, null, 2));Method 3: Using Python
import json
data = '{"name":"John","age":30}'
parsed = json.loads(data)
print(json.dumps(parsed, indent=2))Method 4: Using the Command Line (jq)
echo '{"name":"John"}' | jq .
# Or format a file:
cat data.json | jq .JSON Formatting Best Practices
- Use 2 spaces for indentation (industry standard)
- Sort keys alphabetically for easier navigation
- Minify JSON for production to reduce file size
- Always validate after formatting to catch any errors