JSON Formatter: Complete Guide to Formatting JSON Data
Make your JSON readable and beautiful with proper formatting
Last updated: January 21, 2026 • 6 min read
Why Format JSON?
Well-formatted JSON is easier to read, debug, and maintain. Compare these two examples:
Unformatted (Minified) JSON:
{"name":"John Doe","age":30,"email":"john@example.com","address":{"street":"123 Main St","city":"New York","zip":"10001"},"interests":["coding","reading","hiking"]}Formatted (Beautified) JSON:
{
"name": "John Doe",
"age": 30,
"email": "john@example.com",
"address": {
"street": "123 Main St",
"city": "New York",
"zip": "10001"
},
"interests": [
"coding",
"reading",
"hiking"
]
}The second version is much easier to understand at a glance!
Standard JSON Formatting Rules
1. Indentation
Use consistent indentation (typically 2 or 4 spaces) for each nesting level:
{
"level1": {
"level2": {
"level3": "value"
}
}
}2. One Property Per Line
Each key-value pair should be on its own line:
{
"firstName": "John",
"lastName": "Doe",
"age": 30
}3. Array Formatting
For simple arrays, you can keep items on one line if they're short:
{
"colors": ["red", "green", "blue"]
}For complex arrays or long lists, use one item per line:
{
"users": [
{
"id": 1,
"name": "John"
},
{
"id": 2,
"name": "Jane"
}
]
}4. Spacing Around Colons
Add a space after the colon, but not before:
{
"key": "value" ← Space after colon
}Formatting Tools
Online JSON Formatter
The easiest way to format JSON is using an online tool. Our free JSON formatter instantly beautifies your JSON with proper indentation and spacing.
Command Line
Use built-in tools to format JSON from the terminal:
Python:
echo '{"name":"John","age":30}' | python -m json.toolNode.js:
node -e "console.log(JSON.stringify(JSON.parse(process.argv[1]), null, 2))" '{"name":"John"}' jq (JSON processor):
echo '{"name":"John","age":30}' | jq .In Code
JavaScript/Node.js:
const data = { name: "John", age: 30 };
const formatted = JSON.stringify(data, null, 2);
console.log(formatted);Python:
import json
data = {"name": "John", "age": 30}
formatted = json.dumps(data, indent=2)
print(formatted)PHP:
$data = ["name" => "John", "age" => 30]; $formatted = json_encode($data, JSON_PRETTY_PRINT); echo $formatted;
When to Minify vs. Beautify JSON
Use Formatted (Beautified) JSON For:
- Development: Easier to read and debug
- Configuration files: Better for version control and code reviews
- Documentation: Clearer examples
- APIs during development: Easier to inspect responses
- Logging: More readable log entries
Use Minified JSON For:
- Production APIs: Smaller file sizes = faster transfers
- Storage: Reduces storage space
- Network transmission: Lower bandwidth usage
- Large datasets: Significantly reduces file size
💡 Pro Tip
Use our JSON minifier to compress JSON for production, and our JSON formatter to beautify it for development!
Advanced Formatting Options
Custom Indentation
Different projects may require different indentation levels:
2-Space Indentation (Most Common):
{
"user": {
"name": "John"
}
}4-Space Indentation:
{
"user": {
"name": "John"
}
}Tab Indentation:
{
"user": {
"name": "John"
}
}Sorting Keys Alphabetically
For consistency in version control, you might want to sort keys:
Before (Unsorted):
{
"name": "John",
"age": 30,
"city": "New York"
}After (Sorted):
{
"age": 30,
"city": "New York",
"name": "John"
}Common Formatting Mistakes
1. Inconsistent Indentation
Mixing tabs and spaces, or using different indentation levels:
{
"user": {
"name": "John",
"age": 30
}
}2. Unnecessary Line Breaks
Too many empty lines can make JSON harder to scan:
{
"name": "John",
"age": 30
}3. Misaligned Properties
Don't try to align values vertically - it's hard to maintain:
{
"name": "John",
"age": 30,
"email": "john@example.com"
}Best Practices
- Be consistent: Use the same formatting style across your project
- Use tools: Automate formatting with tools rather than doing it manually
- Version control: Format JSON before committing to avoid unnecessary diffs
- Validate first: Ensure JSON is valid before formatting
- Consider your audience: Format for humans in development, minify for machines in production
Editor Configuration
Configure your code editor to automatically format JSON:
VS Code:
Press Shift + Alt + F or right-click → Format Document
VS Code settings.json:
{
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 2
}
}Tools for JSON Formatting
Conclusion
Proper JSON formatting makes your data more readable, maintainable, and professional. Whether you're developing APIs, writing configuration files, or debugging issues, well-formatted JSON saves time and reduces errors.
Format Your JSON Now
Paste your JSON and get beautifully formatted output instantly - free and no sign-up required!
Format JSON Free →