Why JSON Formatting Matters
JSON is everywhere — APIs, config files, databases, log files, webhooks. But raw JSON from an API response looks like this:
{"users":[{"id":1,"name":"Alice","email":"alice@example.com","roles":["admin","editor"]},{"id":2,"name":"Bob","email":"bob@example.com","roles":["viewer"]}],"total":2,"page":1}
That's technically valid but impossible to read. A JSON formatter transforms it into:
{
"users": [
{
"id": 1,
"name": "Alice",
"email": "alice@example.com",
"roles": ["admin", "editor"]
},
{
"id": 2,
"name": "Bob",
"email": "bob@example.com",
"roles": ["viewer"]
}
],
"total": 2,
"page": 1
}
Instantly readable. You can spot the data structure, find specific values, and catch issues.
What Our JSON Formatter Does
Our free JSON formatter includes:
Format & Beautify
- Pretty print with configurable indentation (2 or 4 spaces, tabs)
- Syntax highlighting — strings, numbers, booleans, null, keys all color-coded
- Collapsible sections for large objects/arrays
Validate
- Real-time validation as you type
- Error messages with exact position (line and column)
- Common error detection: trailing commas, single quotes, unquoted keys, missing brackets
Minify
- Remove all whitespace for production use
- Size comparison — see bytes saved
- One-click copy of minified output
Common JSON Errors and How to Fix Them
| Error | Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Remove the last comma |
| Single quotes | {'name': 'Alice'} | Use double quotes: "name" |
| Unquoted keys | {name: "Alice"} | Quote the key: "name" |
| Missing comma | {"a": 1 "b": 2} | Add comma between pairs |
| Missing bracket | {"users": [{"id": 1} | Close all brackets: ]} |
| Comments | {"a": 1 // comment} | JSON doesn't support comments — remove them |
| Undefined/NaN | {"val": undefined} | Use null instead |
Tip: If your JSON has comments or trailing commas, it's probably JSON5 or JSONC — not standard JSON. Strip the non-standard parts before validating.
JSON Formatting in Code
JavaScript / Node.js
// Pretty print
JSON.stringify(obj, null, 2);
// Minify
JSON.stringify(obj);
// Parse + validate
try {
const data = JSON.parse(jsonString);
} catch (e) {
console.error('Invalid JSON:', e.message);
}
Python
import json
# Pretty print
print(json.dumps(obj, indent=2))
# From file
with open('data.json') as f:
data = json.load(f)
# Validate
try:
json.loads(json_string)
except json.JSONDecodeError as e:
print(f"Invalid: {e}")
Command Line (jq)
# Pretty print
echo '{"a":1,"b":2}' | jq .
# Minify
echo '{"a": 1, "b": 2}' | jq -c .
# Extract value
echo '{"users":[{"name":"Alice"}]}' | jq '.users[0].name'
Go
import "encoding/json"
// Pretty print
formatted, _ := json.MarshalIndent(obj, "", " ")
// Validate
var js json.RawMessage
if json.Unmarshal([]byte(str), &js) != nil {
fmt.Println("Invalid JSON")
}
JSON vs Other Data Formats
| Format | Readable | Size | Comments | Use Case |
|---|---|---|---|---|
| JSON | Good | Medium | No | APIs, configs, data exchange |
| YAML | Excellent | Small | Yes | Config files, CI/CD |
| XML | Verbose | Large | Yes | Enterprise, SOAP APIs |
| TOML | Good | Small | Yes | Config files (Rust, Go) |
| MessagePack | No (binary) | Smallest | No | High-performance data |
| Protocol Buffers | No (binary) | Smallest | N/A | gRPC, microservices |
When to Minify JSON
Minification removes all whitespace. Use it when:
- API responses — smaller payloads = faster load times
- Local storage — browser localStorage has 5-10MB limit
- Network transfer — every byte counts on mobile connections
- Log entries — single-line JSON is easier to grep
Don't minify config files, documentation examples, or anything humans need to read.
JSON Size Optimization Tips
- Shorter key names —
"n"instead of"name"(saves bytes at scale) - Remove null values — if a field is null, omit it entirely
- Use arrays instead of objects for homogeneous data
- Compress with gzip/brotli — 60-80% reduction on JSON payloads
- Consider binary formats (MessagePack, CBOR) for internal services
Try It Free
Our JSON formatter runs entirely in your browser. Your data never leaves your machine. No signup, no limits.
{ } Free JSON Formatter & Validator
Paste JSON, format instantly. Validate, minify, copy — all in your browser.
Open JSON Formatter →More Free Dev Tools
- JWT Decoder — decode and inspect JSON Web Tokens
- Base64 Encoder/Decoder — encode and decode Base64 strings
- UUID Generator — generate UUID v4 and v7
- Hash Generator — MD5, SHA-256, SHA-512
- View all 21+ free tools →