How to Format JSON Online: Complete Guide
Learn how to format JSON online in seconds. This complete guide covers JSON formatting, validation, and debugging with practical examples and free browser tools.
JSON is everywhere. REST APIs return it. Log files dump it. Config files store it. And half the time, it arrives as an unreadable wall of characters — minified, escaped, or just plain broken.
Formatting JSON by hand is a waste of time. This guide shows you how to format JSON online instantly, what good formatting looks like, how to validate structure, and how to debug common JSON errors.
Why Format JSON?
Raw JSON from an API response often looks like this:
{"user":{"id":1,"name":"Alice","roles":["admin","editor"],"preferences":{"theme":"dark","notifications":true}}}
That’s valid JSON. It’s also completely unreadable. A formatted version looks like this:
{
"user": {
"id": 1,
"name": "Alice",
"roles": ["admin", "editor"],
"preferences": {
"theme": "dark",
"notifications": true
}
}
}
Same data. Ten times easier to read, debug, and reason about.
How to Format JSON Online (Step by Step)
Step 1: Copy your JSON
Grab the JSON string from your API response, log file, config, or clipboard. It doesn’t have to be valid — the formatter will tell you if it isn’t.
Step 2: Open the formatter
Use the JSON Formatter — it handles formatting, validation, and error detection in one step.
Step 3: Paste and format
Paste your JSON into the input field and click Format (or it may format automatically as you type). The tool will:
- Indent nested objects and arrays consistently
- Highlight syntax with color coding
- Show line numbers for easy navigation
- Report errors with exact line and character positions
Step 4: Copy the result
Copy the formatted output and use it — paste it back into your editor, share it with a teammate, or use it to file a bug report.
That’s it. No signup required.
JSON Formatting Rules
Understanding why formatting works helps you avoid writing bad JSON in the first place.
Objects
Objects use curly braces. Keys must be double-quoted strings. Values can be any JSON type.
{
"name": "Alice",
"age": 30,
"active": true
}
Arrays
Arrays use square brackets. Items are comma-separated. No trailing comma.
["red", "green", "blue"]
Nested Structures
Objects and arrays can be nested to any depth.
{
"user": {
"id": 42,
"tags": ["developer", "admin"],
"address": {
"city": "Tokyo",
"zip": "100-0001"
}
}
}
Valid Value Types
| Type | Example |
|---|---|
| String | "hello" |
| Number | 42, 3.14, -7 |
| Boolean | true, false |
| Null | null |
| Object | {"key": "value"} |
| Array | [1, 2, 3] |
Common JSON Errors and How to Fix Them
Trailing Commas
Invalid:
{
"name": "Alice",
"age": 30,
}
Fixed: Remove the trailing comma after the last property.
{
"name": "Alice",
"age": 30
}
JSON does not allow trailing commas. JavaScript does (in objects and arrays), which creates confusion. Use a formatter to catch them.
Unquoted Keys
Invalid:
{
name: "Alice"
}
Fixed: All keys must be double-quoted strings in JSON.
{
"name": "Alice"
}
Single Quotes
Invalid:
{
'name': 'Alice'
}
Fixed: JSON only uses double quotes, not single quotes.
{
"name": "Alice"
}
Missing Quotes Around String Values
Invalid:
{
"status": active
}
Fixed:
{
"status": "active"
}
Unless the value is true, false, null, or a number, it needs quotes.
Unescaped Special Characters
Invalid:
{
"path": "C:\Users\alice"
}
Fixed: Backslashes must be escaped with another backslash.
{
"path": "C:\\Users\\alice"
}
Other characters that need escaping: \", \n (newline), \t (tab), \r (carriage return).
Formatting JSON in Code
Sometimes you need to format JSON programmatically rather than using a browser tool.
JavaScript
const raw = '{"name":"Alice","age":30}';
const parsed = JSON.parse(raw);
const formatted = JSON.stringify(parsed, null, 2);
console.log(formatted);
The third argument to JSON.stringify controls indentation. 2 means 2 spaces; use '\t' for tabs.
Python
import json
raw = '{"name":"Alice","age":30}'
parsed = json.loads(raw)
formatted = json.dumps(parsed, indent=2)
print(formatted)
Node.js (command line)
echo '{"name":"Alice","age":30}' | node -e "
let d='';
process.stdin.on('data',c=>d+=c);
process.stdin.on('end',()=>console.log(JSON.stringify(JSON.parse(d),null,2)));
"
Or with Python’s built-in module:
echo '{"name":"Alice","age":30}' | python3 -m json.tool
JSON Formatting in Different Contexts
API Development
When building APIs, format JSON in error responses and documentation. Minify in production payloads for performance, but always log formatted JSON for debugging.
Config Files
Keep config files formatted in version control. Minified config files make diffs unreadable and code review painful.
Log Analysis
When logs contain JSON fields, use a formatter to inspect individual log entries. Pair with a JSON diff tool to compare entries across time.
Clipboard Debugging
Grab JSON from browser DevTools network tab → paste into formatter → read the structure clearly. This saves significant time when debugging API integrations.
When Formatting Isn’t Enough: JSON Schema Validation
Formatting tells you if JSON is syntactically valid. Schema validation tells you if it’s semantically correct — whether the right fields are present, the right types are used, and required properties aren’t missing.
For API development, use JSON Schema to define and validate your request/response contracts. The JSON Schema Generator can generate a schema from a sample JSON object automatically.
Format Faster with DevPlaybook Pro
The free JSON Formatter handles most needs. DevPlaybook Pro adds:
- Saved sessions — come back to the same JSON payload without repasting
- Team workspaces — share formatted payloads with teammates via link
- JSON diff — compare two payloads side by side with highlighted changes
- Bulk formatting — format multiple JSON files via API
Go Pro and spend less time on JSON, more time shipping.
Free Newsletter
Level Up Your Dev Workflow
Get new tools, guides, and productivity tips delivered to your inbox.
Plus: grab the free Developer Productivity Checklist when you subscribe.
Found this guide useful? Check out our free developer tools.
Affiliate disclosure: Some links below are affiliate links — we may earn a small commission at no extra cost to you. Learn more.
Recommended Tools & Resources
DigitalOcean
$200 credit for new users. Simple, affordable cloud hosting for developers.
GitHub Student Pack
Free access to 100+ developer tools. Perfect for students and new devs.
Vercel
Deploy frontend apps instantly. Free tier is generous for side projects.
DevPlaybook Products
Boilerplates, scripts & AI toolkits to 10x your dev workflow.