JSON: How to Validate, Format, and Not Break It
An API returns a response as a single 5,000-character line, and you need to know whether a status field is in there. Or the other way around: you wrote a config, the validator complains at character 1, and everything looks perfect to the eye. Let's see how to get JSON in order quickly and stop stepping on the same rakes.
What JSON forgives — and what it doesn't
JSON is a strictly formal format, and that's a good thing: the same document reads the same everywhere. But that formality is exactly what stings. These five mistakes cover almost every "what is wrong with it now?" case:
- a trailing comma after the last element of an array or object — allowed in a JavaScript object, forbidden in JSON;
- single quotes instead of double — strings and keys must use " ";
- // or /* */ comments — they simply don't exist in JSON (JSON5 and YAML were invented for configs with comments);
- unquoted keys — name: won't parse; it has to be "name":;
- a real line break inside a string value — it must be the escape sequence \n instead.
Formatting and minification
The same JSON exists in two forms. Pretty-printed — with indentation and line breaks, made for human eyes and for finding the right spot. Minified — a single line with no spaces: less traffic, and that's how data usually travels between servers. Switching between the two is easy in the JSON formatter: paste a string and you get an indented tree; hit minify and you get the compact version back. Syntax errors are highlighted immediately, with their location.
When the file is huge
In a large response, searching by eye is pointless. If you need to pull out a specific field or check that the structure matches expectations (required fields, types), two tools come in handy. The JSON path finder locates the path to a value by substring — the fastest way to see where the thing you're looking for actually lives. And the JSON Schema validator checks the document against a declared schema — indispensable when you're receiving data from an external API.
JSON Formatter & Validator
Format, beautify, validate, and minify JSON data with tree view
JSON Path Finder
Find paths to values and keys in JSON objects with powerful search
JSON Schema Validator
Validate JSON data against a JSON Schema with detailed error messages and draft-07 support
Frequently asked questions
How is JSON different from a JavaScript object?
It looks almost the same, but JSON is stricter: keys must be double-quoted, and functions, undefined and comments are not allowed. A JavaScript object is a live structure with methods; JSON is only a text data-exchange format.
What makes JSON fail validation most often?
Three classics: a trailing comma after the last item, single quotes instead of double ones, and unquoted keys. Less often — unescaped line breaks inside a string.
Does JSON support comments?
No, the specification forbids them — comments break parsers. If you need notes, put them in a separate field like «_comment» or in the documentation next to the file.