
Complete Guide to JSON Formatting and Validation
JSON's Syntax Rules Are Strict -- And Unforgiving
Unlike some more forgiving formats, JSON has strict syntax rules -- a single misplaced comma, an unquoted key, or a stray trailing comment breaks the entire file, with no partial parsing or graceful degradation. This strictness is deliberate: it's what makes JSON reliably parseable across every language and platform without ambiguity, but it also means a small, easy-to-miss typo can produce a confusing error message or an outright parsing failure somewhere downstream, far from where the actual mistake was made. Understanding the rules precisely makes debugging these failures far faster than guessing.
The Core Rules
Keys must be double-quoted strings -- single quotes or unquoted keys, both common in JavaScript object literals, are invalid in strict JSON and a frequent source of confusion for anyone coming from JavaScript specifically, where object keys can be written far more loosely. No trailing commas are allowed after the last item in an object or array, unlike some other languages that tolerate them -- a comma left over from reordering or adding items is one of the single most common JSON syntax errors. Strings must use double quotes, not single quotes, with no exceptions. And no comments are allowed anywhere in standard JSON, which surprises many developers used to being able to annotate configuration files, and is one of the more frequently requested (but never adopted) features for the format.
Formatting & Validating

Paste any JSON into the JSON Formatter & Validator to pretty-print it with proper indentation, and get the exact location of any syntax error -- pinpointing the specific line and character where parsing failed saves substantial debugging time compared to scanning a large, minified document by eye looking for a single misplaced character.
Why JSON Gets Minified in the First Place
APIs and production systems often strip all unnecessary whitespace from JSON to reduce transfer size -- great for machines and network efficiency, genuinely unreadable for humans trying to inspect or debug it. Formatting reverses this for debugging or documentation purposes, restoring the indentation and line breaks that make a JSON structure's hierarchy visible at a glance rather than buried in an unbroken wall of characters.
Working With JSON Strings Inside Other Text

When a JSON string needs to be embedded inside another JSON document or a config file, it needs to be escaped -- special characters like quotes and backslashes within the inner string need to be marked so the outer parser doesn't misinterpret them as structural syntax rather than literal string content. See the JSON Escape Tool and JSON Unescape Tool for handling this correctly, rather than attempting the escaping manually and risking a subtle mistake.
Common JSON Errors and What They Actually Mean
Beyond the core rules above, a few specific error patterns come up constantly: a missing closing bracket or brace, often from a copy-paste that cut off part of the structure; mismatched bracket types (opening with a square bracket but closing with a curly brace, or vice versa); and duplicate keys within the same object, which some parsers silently accept (keeping only the last value) while others reject outright, making this an easy source of inconsistent behavior across different tools handling the same file.
Why Manual JSON Editing Is Riskier Than It Looks
Hand-editing a JSON file directly in a plain text editor, without validation, is a common source of the exact errors described above -- a deleted or misplaced character during editing is easy to introduce and hard to spot by eye in a dense document, especially one that's already minified or deeply nested. Running any manually edited JSON through a validator before using it, rather than assuming a small hand edit couldn't have broken anything, catches these mistakes before they surface as a confusing downstream failure somewhere else in a system.
Frequently Asked Questions
Why does my JSON look invalid even though it displays fine?
Some systems are more lenient than the strict JSON spec (accepting trailing commas or comments) -- code that displays your data might tolerate errors that a strict validator (and many production APIs) will reject, which is exactly why validating against the actual spec matters even when a looser tool seems to accept the file without complaint.
Is JSON5 or JSONC the same as standard JSON?
No -- these are separate, extended formats that add features like comments and trailing commas, popular in certain configuration file contexts, but they aren't valid standard JSON and won't parse correctly with a strict JSON parser expecting the base specification.
Can JSON represent every kind of data, including dates?
Not natively -- JSON has no built-in date type, so dates are typically represented as ISO 8601 formatted strings or Unix timestamps by convention, with the actual date-object conversion handled by whatever application reads the JSON, not by the JSON format itself.
Why do some APIs return errors for JSON that other tools accept without complaint?
Different tools implement varying levels of strictness -- some parsers are lenient and quietly tolerate deviations from the strict spec (trailing commas, single-quoted strings), while production APIs typically enforce the full specification exactly, rejecting anything that doesn't conform. Testing against a strict validator before sending data to a production API catches these mismatches early.
Is there a size limit to how large a JSON document can be?
The JSON specification itself doesn't impose a size limit, but individual parsers, APIs, and browsers may impose their own practical limits based on available memory or configured request-size caps -- check the specific system you're working with if you're dealing with an unusually large JSON payload.
Why do numbers sometimes lose precision when passed through JSON?
JSON's number type is based on standard floating-point representation, which has known precision limits for very large integers or numbers requiring extreme decimal precision -- for values where exact precision genuinely matters (large financial IDs, for instance), representing the number as a string rather than a native JSON number is a common workaround.
Can JSON contain a top-level value that isn't an object or array, like just a plain string or number?
Under the modern JSON specification, yes -- a bare string, number, boolean, or null is valid as the entire document, though in practice most real-world JSON documents use an object or array as the top-level container since that structure is what most parsing code and APIs actually expect.

Comments (0)
No comments yet. Be the first to share your thoughts.