JSON is everywhere — APIs, config files, databases. But unformatted JSON is nearly unreadable. This guide covers what JSON formatting means, why it matters, and how to do it efficiently.
What Is JSON Formatting?
Formatting (or “pretty-printing”) JSON means adding consistent indentation and line breaks so the structure is easy to read. Compare:
Raw:
{"name":"Alice","age":30,"skills":["js","python"]}
Formatted:
{
"name": "Alice",
"age": 30,
"skills": [
"js",
"python"
]
}
Same data, dramatically different readability.
JSON Syntax Rules
Before formatting, the JSON must be valid. Key rules:
- Strings must use double quotes —
"key", not'key' - Keys must be strings (quoted)
- Trailing commas are not allowed:
[1, 2, 3,]is invalid - Comments are not allowed in standard JSON
- Values can be: string, number, object, array,
true,false,null
Common JSON Errors
| Error | Example | Fix |
|---|---|---|
| Trailing comma | {"a":1,} | Remove the comma |
| Single quotes | {'a':'b'} | Use double quotes |
| Unquoted key | {a: 1} | Quote the key |
| Undefined value | {"x": undefined} | Use null instead |
| Comments | // comment | Remove — not valid JSON |
How to Format JSON Online
The fastest way to format JSON is with a browser-based tool — no install, no copy-paste into an IDE.
Try the ZeroTool JSON Formatter →
It formats instantly as you type, highlights syntax errors inline, and lets you copy the result in one click.
What to look for in a JSON formatter
- Real-time validation — catches errors as you type
- Syntax highlighting — makes nested structures scannable
- Error messages — tells you exactly where parsing failed
- Copy button — one-click to clipboard
Formatting JSON in Code
JavaScript / Node.js
const ugly = '{"name":"Alice","age":30}';
const pretty = JSON.stringify(JSON.parse(ugly), null, 2);
console.log(pretty);
JSON.stringify(value, replacer, space) — the third argument sets indent width.
Python
import json
ugly = '{"name": "Alice", "age": 30}'
pretty = json.dumps(json.loads(ugly), indent=2)
print(pretty)
Command Line (jq)
echo '{"name":"Alice"}' | jq .
# or format a file:
cat data.json | jq .
jq is the standard Unix tool for JSON processing. Install with brew install jq or apt install jq.
Minifying JSON
The reverse of formatting: remove all whitespace to reduce file size. Useful before sending data over the wire.
// JavaScript
const minified = JSON.stringify(JSON.parse(pretty));
The ZeroTool JSON Formatter also supports minification — paste your formatted JSON and click Minify.
JSON Schema Validation
Formatting only checks syntax. If you need to validate the shape of your data (required fields, types, patterns), use JSON Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["name", "age"],
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
}
}
Tools like ajv (Node.js) or jsonschema (Python) can validate against a schema programmatically.
Tips for Working with Large JSON
- Collapse sections — good formatters let you fold object/array nodes
- Search by key — faster than scrolling
- Paginate arrays — if an array has thousands of items, render only visible rows
- Use streaming parsers — for files over 50 MB, libraries like
oboe.jsor Python’sijsonparse without loading everything into memory
Summary
| Task | Tool |
|---|---|
| Quick format / validate | ZeroTool JSON Formatter |
| CLI formatting | jq . |
| JavaScript | JSON.stringify(obj, null, 2) |
| Python | json.dumps(obj, indent=2) |
| Schema validation | ajv, jsonschema |
Clean JSON is faster to debug, easier to review in diffs, and less likely to hide errors. Use a formatter every time.