This JSON formatter makes messy JSON easy to read and tells you where it is broken. JSON is a text format that programs use to share data, often through a web API.
How to use the JSON formatter online
- Paste your JSON.
- Choose format, minify or validate.
- If there is an error, go to the line and column shown.
- Use the tree view to open and close parts of the data.
- To compare, paste a second JSON text.
JSON formatter: beautify example
This is hard to read:
{"name":"Asha","skills":["Java","SQL"],"active":true}
After you beautify it:
{
"name": "Asha",
"skills": ["Java", "SQL"],
"active": true
}
The tool may put each list item on its own line. The data is still the same, because spaces between JSON items have no meaning.
Minify does the reverse. It removes extra spaces and lines, which makes a file smaller to send.
JSON formatter and validator: common errors
| Wrong | Right | Reason |
|---|---|---|
{'a': 1} |
{"a": 1} |
Use double quotes |
{a: 1} |
{"a": 1} |
Keys need quotes |
[1, 2,] |
[1, 2] |
No comma after the last item |
{"a": True} |
{"a": true} |
true, false and null are lowercase |
{"a": 01} |
{"a": 1} |
No leading zeros |
An error message may point just after the real problem. If line 5 looks fine, check the end of line 4 for a missing comma or quote.
Common mistake: A common mistake beginners make is copying a JavaScript object and expecting it to be valid JSON. JavaScript allows single quotes, unquoted keys and comments. JSON does not.
JSON formatter viewer: reading the tree
The tree view shows objects and lists as branches. Close the parts you do not need and open one branch at a time. This helps you find the path to a value.
For the data below, the path to "Hyderabad" is user.address.city:
{
"user": {
"address": { "city": "Hyderabad" }
}
}
List positions start at 0. The first skill in a list is skills[0].
JSON formatter: compare online
Paste two JSON texts to see what changed. This helps when an API worked yesterday and fails today.
Two rules help you read the result:
- Key order does not matter.
{"a":1,"b":2}and{"b":2,"a":1}hold the same data. - List order does matter.
[1,2]and[2,1]are different.
Also compare types. The number 5 and the text "5" look alike but can break a program.
Pro tip: Format both texts first. Differences are much easier to see when the layout matches.
Keep private data out
Do not paste passwords, API keys, tokens or customer data into any online tool. Replace them with sample values such as "xxxx" first. If a secret must be created, use the password generator and store it safely.
Where JSON is used
JSON carries data between a page and a server. Start with what is a REST API, then see it in the Node.js tutorial. Document databases store similar shapes, as the MongoDB tutorial shows. Front-end developers meet JSON lists often, so JavaScript array methods are worth learning next.
In code, JavaScript has two built-in functions: JSON.parse reads JSON text, and JSON.stringify writes it. JSON.stringify(data, null, 2) formats it with two spaces.
