JSON (JavaScript Object Notation) is the universal language of modern APIs, configuration files, and data exchange. Whether you're debugging an API response, reading a config file, or preparing data for a webhook โ a good JSON formatter saves hours of squinting at unreadable strings.
What is JSON Formatting (Pretty Print)?
Raw JSON from APIs often comes as a single compressed line โ no spaces, no indentation. Pretty printing adds line breaks and indentation to make it human-readable:
Before formatting (minified):
{"name":"Rahul","salary":80000,"city":"Mumbai","skills":["Java",".NET","SQL"]}
After formatting (pretty print):
{
"name": "Rahul",
"salary": 80000,
"city": "Mumbai",
"skills": [
"Java",
".NET",
"SQL"
]
}
Common JSON Syntax Errors and Fixes
| Error | Wrong | Correct |
|---|---|---|
| Single quotes | {'name': 'Rahul'} | {"name": "Rahul"} |
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Unquoted key | {name: "Rahul"} | {"name": "Rahul"} |
| Comments | {"a": 1 // comment} | Remove comments โ JSON doesn't support them |
| Undefined value | {"val": undefined} | {"val": null} |
JSON vs XML vs YAML
| Format | Readability | Size | Best For |
|---|---|---|---|
| JSON | Good | Compact | REST APIs, web apps, JavaScript |
| XML | Verbose | Large | Enterprise systems, SOAP, legacy |
| YAML | Excellent | Compact | Config files, Docker, Kubernetes |
When to Minify JSON
Minifying removes all whitespace and reduces file size. Use minified JSON for:
- API responses in production (saves bandwidth)
- Storing JSON in databases
- Embedding JSON in HTML data attributes
- Web performance optimization (smaller payload = faster page)
Never minify JSON that humans need to read directly โ like config files or documentation examples.