Development7 min read
How to Format JSON: A Complete Guide for Developers
JSON (JavaScript Object Notation) is the most common data format on the web. But compact JSON is nearly impossible to read. This guide covers everything you need to know about formatting, validating, and working with JSON.
What Is JSON Formatting?
JSON formatting (also called "pretty printing" or "beautifying") transforms compact, minified JSON into structured, indented text that humans can easily read. For example:
Minified (hard to read):
{"name":"John","age":30,"address":{"city":"NYC","zip":"10001"}}Formatted (easy to read):
{
"name": "John",
"age": 30,
"address": {
"city": "NYC",
"zip": "10001"
}
}How to Format JSON Online
- Go to our JSON Formatter
- Paste your JSON in the input panel
- Click "Beautify" for formatted output or "Minify" to compress
- Copy or download the result
Common JSON Syntax Errors
- Trailing commas:
{"a":1,}— remove the last comma - Single quotes:
{'a':1}— JSON requires double quotes - Unquoted keys:
{a:1}— keys must be quoted strings - Comments: JSON does not support
//or/* */comments
JSON Formatting in Code
JavaScript
JSON.stringify(data, null, 2) // 2-space indent
JSON.stringify(data) // minifiedPython
import json
json.dumps(data, indent=2) # formatted
json.dumps(data) # minifiedCommand Line
cat data.json | python -m json.tool # Python
cat data.json | jq . # jqRelated Tools
- JSON Formatter & Validator — format, validate, and minify JSON
- JSON Stringify — escape JSON for embedding in code
- JSON to CSV — convert JSON to spreadsheet format
- CSV to JSON — convert CSV data to JSON
- YAML Formatter — format YAML, a JSON alternative