JSON (JavaScript Object Notation) is the lingua franca of modern web APIs. Whether you are debugging a REST endpoint, configuring a cloud service, or building a frontend app, you encounter JSON every day. Yet reading raw, minified JSON is a painful experience — one missing comma can break an entire payload. Here is everything you need to know about JSON formatting, validation, and debugging.
What Is JSON Formatting?
JSON formatting (also called "pretty-printing") transforms compressed, hard-to-read JSON into an indented, human-readable structure. A JSON formatter takes something like this:
{"name":"DevToolsHub","tools":[{"name":"JSON Formatter","url":"/json-formatter"},{"name":"Base64","url":"/base64"}],"active":true}And turns it into this:
{
"name": "DevToolsHub",
"tools": [
{
"name": "JSON Formatter",
"url": "/json-formatter"
},
{
"name": "Base64",
"url": "/base64"
}
],
"active": true
}Why Formatting Matters
- Find errors faster — malformed JSON is immediately obvious when you can see the structure
- Compare responses — formatted JSON makes side-by-side comparison of API outputs easy
- Share readable snippets — formatted JSON is easier to paste into documentation, issues, or PRs
- Debug configurations — many cloud and DevOps tools (Terraform, Kubernetes, AWS) output JSON
Common JSON Mistakes to Watch For
1. Trailing Commas
JavaScript allows trailing commas in objects and arrays. JSON does not. This is one of the most common sources of parse errors:
// Invalid JSON (trailing comma)
{
"name": "DevToolsHub", ← remove this comma
}2. Unquoted Keys
In JavaScript, object keys can be unquoted identifiers. JSON requires all keys to be wrapped in double quotes:
// Invalid JSON (unquoted key)
{ name: "DevToolsHub" }
// Valid JSON
{ "name": "DevToolsHub" }3. Single Quotes Instead of Double Quotes
JSON only allows double quotes ("). Single quotes (') are not valid, even though many programming languages accept them for string literals.
4. Undefined or NaN Values
JSON supports null, true, and false, but not undefined or NaN. These values cause JSON.stringify() to silently drop keys or convert them to null.
JSON Formatting Best Practices
Use 2-Space Indentation
The standard for JSON formatting is 2-space indentation. It provides enough visual structure without wasting horizontal space. Some tools default to 4 spaces — configure them to use 2 for consistency with most API documentation.
Validate Before You Use
Always validate JSON before feeding it to your application. A good JSON formatter with validation catches errors immediately and shows you exactly where the problem is. This saves hours of debugging.
Compress for Production
When sending JSON over the wire, use the compression mode to strip all whitespace. JSON.stringify(value) (without spacing arguments) produces compressed output. A typical API response shrinks by 30-50% when compressed — saving bandwidth and improving load times.
Putting It All Together
Whether you are a seasoned backend engineer or a frontend developer learning the ropes, mastering JSON formatting is a foundational skill. The next time you copy a curl response, paste it into a JSON formatter before trying to read it. Your eyes — and your debugging efficiency — will thank you.