If you've worked with APIs, configuration files, or any kind of web data exchange, you've almost certainly encountered JSON. It's everywhere — inside the response when you call an API, nested inside a package.json file, powering database records in document stores like MongoDB. And yet, despite JSON's ubiquity, formatting errors remain one of the most common — and most frustrating — sources of bugs for developers at every skill level. A single missing comma or an unquoted key can silently break an entire application.
This guide takes a practical look at JSON formatting: what the rules actually are, why violations happen so often, how to debug them efficiently, and how tools like our JSON Formatter & Validator can save you hours of debugging. Whether you're a seasoned developer who just needs a quick refresher or someone newer to working with structured data, there's something here for you.
What JSON Actually Is (And What It Isn't)
JSON stands for JavaScript Object Notation, and despite the name, it is language-agnostic. Python, Java, Go, PHP, Ruby — every modern language can parse and generate JSON natively or through a standard library. It was designed by Douglas Crockford in the early 2000s as a lightweight alternative to XML for transmitting data between a server and a web application.
The key thing to understand about JSON is that it is a data interchange format, not a programming language. It has no functions, no logic, and no comments. It exists purely to describe structured data in a way that both humans and machines can read. This simplicity is its greatest strength — and the source of many formatting mistakes, because any deviation from the strict spec causes a parse failure.
JSON supports exactly six data types:
- String: A sequence of Unicode characters enclosed in double quotes. Single quotes are NOT valid JSON.
- Number: An integer or floating-point number. Not enclosed in quotes. Scientific notation (1e10) is allowed.
- Boolean: Exactly
trueorfalse— lowercase only. - Null: Exactly
null— lowercase only. Represents the absence of a value. - Array: An ordered list of values of any type, enclosed in square brackets
[]. - Object: An unordered collection of key-value pairs, enclosed in curly braces
{}. Keys must be strings in double quotes.
The Most Common JSON Formatting Mistakes
Most JSON errors fall into a surprisingly small number of categories. Knowing them makes debugging much faster, because instead of reading every character of a large JSON blob, you know where to look first.
1. Trailing Commas
This is perhaps the single most common mistake, especially for developers who come from JavaScript, Python, or languages that tolerate trailing commas in arrays and object literals. In strict JSON, a trailing comma after the last item in an object or array is a hard syntax error. For example:
// INVALID JSON — trailing comma
{
"name": "Alice",
"age": 30,
}
The comma after "age": 30 is invalid. JavaScript's JSON.parse(), Python's json.loads(), and virtually every other strict JSON parser will throw a SyntaxError at this point.
2. Single Quotes Instead of Double Quotes
JSON requires that all strings — including object keys — be wrapped in double quotes. Single quotes are valid in JavaScript object literals, but JSON is not JavaScript. This trips up developers who copy-paste data from JavaScript code into a JSON file or API body:
// INVALID — single quotes
{'name': 'Bob'}
// VALID — double quotes
{"name": "Bob"}
3. Comments in JSON
JSON does not support comments — not // style, not /* */style, not any style. The spec is absolute on this. When you need comments in configuration files, consider using YAML (which does support comments) or JSON5 (an extension of JSON that allows comments). But if your system expects strict JSON, remove all comments before parsing.
4. Undefined, NaN, and Infinity
JavaScript developers occasionally try to serialize values like undefined, NaN, or Infinity into JSON. None of these are valid JSON values. If you call JSON.stringify(NaN) in JavaScript, you'll get the string "null" — which is valid JSON, but likely not the intended behavior. Always handle these edge cases explicitly in your serialization logic.

A well-structured JSON document is immediately readable — proper formatting makes debugging and collaboration dramatically easier.
Formatting vs. Minifying: When to Use Each
JSON exists in two forms in practice: pretty-printed (human-readable with indentation) and minified (machine-readable, stripped of all whitespace). Understanding when to use each is essential.
Pretty-printed JSON uses consistent indentation (typically 2 or 4 spaces) and newlines to visually show the nesting structure. Use it when:
- Working in configuration files that humans read and edit (like
package.json,tsconfig.json) - Debugging API responses — it's much easier to spot a missing field in formatted JSON
- Storing JSON in version control, where readable diffs matter
- Building documentation or examples for other developers
Minified JSON removes all unnecessary whitespace and newlines, reducing file size by 15–40% in most cases. Use it when:
- Sending API responses over a network — smaller payload means faster transfer
- Storing JSON in a database where storage cost matters
- Embedding JSON in JavaScript bundles for production
Our JSON Formatter handles both directions: paste any valid JSON to auto-format it with configurable indentation, or click Minify to strip it down for production use. It also validates the JSON as you type, highlighting errors in real time.
Working With Nested JSON Structures
Real-world JSON is rarely flat. An API response for a user profile might have nested objects for address, preferences, and subscription details, each with their own nested arrays. Deeply nested JSON is where readability collapses fastest without proper formatting, and where manually checking structure becomes nearly impossible.
When dealing with deeply nested JSON, a few practices make life considerably easier:
- Use a formatter with tree view: Rather than reading raw text, a tree-view representation lets you collapse and expand sections to understand the overall shape of the data without reading every value.
- Use JSON Schema for validation: If you're working with a fixed data structure (like an API contract), define a JSON Schema and validate your data against it. This catches structural problems before they reach production.
- Use jq for command-line JSON processing: If you work in a terminal, the
jqtool is a powerful lightweight processor for querying and transforming JSON. Commands likejq '.users[] | .email'let you extract specific fields from complex structures. - Split large JSON files: If you're dealing with a JSON file that has thousands of records, consider breaking it into smaller files or migrating to a proper database. JSON was never designed to be a high-performance data store.
JSON vs. Related Formats
JSON is not the only game in town. Understanding when to reach for alternatives helps you make better architectural decisions.
- YAML: More human-readable than JSON, supports comments, and uses indentation instead of braces. Excellent for configuration files (Docker Compose, Kubernetes, GitHub Actions). But its whitespace-sensitivity makes it more error-prone for humans editing manually.
- XML: Verbose but extremely powerful for document-centric data. Still heavily used in enterprise systems, SOAP APIs, and document formats like SVG and DOCX. JSON has largely replaced it for API communication, but XML remains the right tool for many structured document scenarios.
- Protocol Buffers (Protobuf): Google's binary serialization format. Far more efficient than JSON in both size and parsing speed. Excellent for high-throughput internal service communication. But it requires schema definition upfront and is not human-readable without tooling.
- TOML: "Tom's Obvious Minimal Language." Designed specifically for configuration files and is the default format for Rust's Cargo and many modern tools. Very readable for simple configs, but struggles with deeply nested structures.
For most web API communication, JSON remains the right choice because of its universality, native browser support, and the enormous ecosystem of tools around it. But knowing when to use alternatives demonstrates real engineering maturity.
Validating JSON in Your Workflow
Validation shouldn't be an afterthought. Here's how to integrate JSON validation at different points in a development workflow:
- In your code editor: Most editors (VS Code, JetBrains IDEs) have built-in JSON validation. Make sure JSON Language Features are enabled and that your files have the
.jsonextension so the editor applies the right language server. - In CI/CD pipelines: Add a JSON validation step to your build pipeline. Tools like
jsonlint(npm package) can be run as part of a pre-commit hook or GitHub Action to catch invalid JSON before it reaches production. - At API boundaries: Validate request and response bodies against a schema. Libraries like
ajv(JavaScript),jsonschema(Python), orcom.networknt:json-schema-validator(Java) all support JSON Schema validation and will catch data shape mismatches at runtime. - With online tools: For quick ad-hoc checks, our JSON Formatter runs entirely in your browser — nothing is sent to a server — making it safe to use for sensitive data during debugging.
Practical JSON Formatting Tips
A few small habits consistently produce cleaner, more maintainable JSON:
- Use 2-space indentation for web projects. Most web tooling and style guides (including the Google JSON Style Guide and Prettier defaults) use 2 spaces. 4 spaces works too, but pick one and be consistent within a project.
- Put one key-value pair per line. Horizontal scrolling in code reviews and git diffs is a productivity killer. Keeping each pair on its own line makes changes easier to review.
- Sort keys alphabetically where possible. Alphabetical key order is not required by the spec, but it makes it much easier to find a specific key in a large object and produces more stable git diffs when values change.
- Escape special characters properly. Backslashes, double quotes, and control characters inside string values must be escaped with a backslash. Common escapes:
\"for quotes,\\for backslash,\nfor newline,\tfor tab. - Validate before committing. Even if you're confident your JSON is valid, run it through a validator before committing. A 10-second check can save 30 minutes of debugging a mysterious runtime error.
Using ToolkitsPlus JSON Tools in Your Daily Workflow
Beyond basic formatting, ToolkitsPlus offers several data tools that complement JSON work. When you're working with tabular data from an API, our CSV to JSON converter lets you instantly transform spreadsheet exports into properly structured JSON arrays. When debugging a complex API, the JSON Formatter gives you a collapsible tree view that makes even 10,000-line responses navigable. All processing happens client-side, so no data leaves your browser.
The best development workflows minimize context-switching. Having reliable, fast, browser-based tools means you spend less time setting up environments and more time solving actual problems. That's the goal behind every tool we build at ToolkitsPlus — not just convenience, but a genuine reduction in friction for everyday developer tasks.
Conclusion
JSON's simplicity is deceptive. Six data types and a strict syntax — how complicated can it be? But in practice, the strictness is exactly what bites developers. A trailing comma, a single-quoted string, or an accidentally commented line can silently break things in production. Building good habits around formatting, validation, and tooling pays dividends every single day.
Use a formatter. Validate early and often. Understand when JSON is the right tool and when a different format might serve better. And lean on browser-based utilities like our JSON Formatter to make those routine checks faster and less painful. Good tooling lets you focus on what actually matters: building things that work.