The Two Faces of JSON
Minified JSON removes all whitespace that isn't part of string values, producing the smallest possible representation for network transmission. Pretty-printed JSON adds indentation (typically 2 or 4 spaces) and line breaks to expose the hierarchical structure visually. The data content is identical — only whitespace differs.
Standard Indentation Conventions
Two spaces per nesting level is the most common convention in JavaScript. Four spaces is common in many other languages. The key is consistency within a project — choose a convention and apply it uniformly.
When Formatting Reveals Problems
Formatting JSON is often the first step in debugging data issues. When minified JSON is expanded, missing commas, mismatched brackets, and incorrect nesting become immediately visible. A JSON formatter that simultaneously validates syntax is an essential debugging tool.
Client-Side vs Server-Side Formatting
Server-side JSON formatting is wasteful — it transmits extra whitespace over the network. The standard practice is to serve minified JSON in production and use browser tools or dedicated formatters to make it readable when needed.
JSON formatting is a fundamental readability and debugging tool. Keep JSON minified in production, pretty-print it for human inspection, and use a formatter that validates syntax simultaneously.