JSON (JavaScript Object Notation) is the de facto standard for data exchange between APIs, services, and applications. Whether you're debugging a REST API response, writing a configuration file, or reviewing a data export, being able to quickly read and validate JSON is an essential developer skill.
What is JSON formatting?
APIs often return minified JSON — all the data on a single line with no extra whitespace. This minimizes network transfer size but makes the data nearly impossible to read. JSON formatting (also called prettifying or beautifying) adds consistent indentation and line breaks so the structure is immediately visible.
For example, the minified JSON {"name":"Alice","age":30,"active":true} becomes:
{
"name": "Alice",
"age": 30,
"active": true
}
The most common JSON syntax errors
JSON has stricter syntax than JavaScript objects. These are the mistakes that cause parse errors most often:
- Trailing commas. JSON does not allow a comma after the last element in an array or object.
[1, 2, 3,]is invalid JSON — it's valid JavaScript but will break any JSON parser. - Single quotes. All strings in JSON must use double quotes.
{'key': 'value'}is not valid JSON. - Unquoted keys. Object keys must always be strings wrapped in double quotes.
{key: "value"}is invalid. - Comments. JSON has no comment syntax. Adding
// commentor/* block */will cause a parse error. - Undefined and functions. JSON supports only: objects, arrays, strings, numbers, booleans, and null.
undefined, functions, and dates (as objects) are not valid JSON values.
Validating JSON
Validation confirms that a JSON string is syntactically correct. Any modern programming language can validate JSON: JSON.parse() in JavaScript throws a SyntaxError on invalid input; Python's json.loads() raises json.JSONDecodeError. An online JSON formatter does the same thing and immediately reports which line contains the error.
When to minify vs. when to prettify
Minify (remove all whitespace) when serving JSON over a network API where response size matters. A few hundred bytes of whitespace may seem trivial, but at millions of requests per day it adds up, and many APIs return large payloads with deeply nested objects.
Prettify when writing JSON by hand (configuration files, test fixtures, documentation), reviewing API responses in debugging sessions, or committing JSON to version control where readable diffs matter.
Tools for JSON formatting
You don't need to install anything to format JSON. Use the JSON Formatter on TextUtils to paste your JSON, instantly beautify or minify it, and see any validation errors highlighted — all in your browser with no data sent to any server.
For large files or automated pipelines, jq is the standard command-line tool: cat data.json | jq . formats and pretty-prints any JSON file, and its query language lets you extract specific fields.