JSON (JavaScript Object Notation) is the most common format for sending data between apps and APIs. It is simple, but a long JSON response on one line is almost impossible to read. Formatting fixes that.
What JSON looks like
{"name":"Asha","age":29,"skills":["php","sql"],"address":{"city":"Pune"}}
The same data, formatted:
{
"name": "Asha",
"age": 29,
"skills": ["php", "sql"],
"address": {
"city": "Pune"
}
}
Nothing changed except spacing and line breaks, but the structure is now clear.
The building blocks
- Objects use curly braces and hold
"key": valuepairs. - Arrays use square brackets and hold a list of values.
- Strings use double quotes.
- Numbers, true, false and null are written without quotes.
Formatting, minifying and validating
- Formatting (pretty printing) adds indentation so people can read the data.
- Minifying removes the spaces to make the data smaller for sending.
- Validating checks that the JSON is correct. A single missing comma makes the whole text invalid.
How to format JSON online
- Open the JSON Formatter.
- Paste your JSON.
- Run the tool and read the formatted result. Copy it with the copy button.
- If you get an error, read the message: it usually points to the problem. Our guide to common JSON errors explains the usual causes.
You can also check a document with the JSON Validator.
JSON and YAML
YAML is another data format that is common in configuration files. It uses indentation instead of braces. If you work with configuration, the YAML Validator helps you catch indentation mistakes.
Good habits
- Format JSON before you read, compare or share it.
- Validate it before sending it to an API.
- Never paste secrets such as passwords or private keys into any online tool you do not control.