JSON is everywhere, in APIs, config files, and the structured data (schema markup) that powers rich results. But JSON is strict: a single misplaced comma breaks the whole thing. Learning to format JSON so it is readable and to validate it so it actually works saves hours of frustrating debugging. This guide covers the syntax rules, the errors you will hit, and when to prettify versus minify.
What JSON is
JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data as key-value pairs and lists. It is human-readable, language-independent, and the default way data travels between systems on the web. Its strictness is a feature, it is unambiguous, but it also means the rules are non-negotiable: get one detail wrong and a parser rejects the entire document rather than guessing what you meant.
The syntax rules that trip people up
Most JSON errors come from a short list of rule violations:
- Keys must be in double quotes. Single quotes or unquoted keys are invalid.
- No trailing commas. A comma after the last item in an object or array breaks it, one of the most common mistakes.
- Strings use double quotes, never single.
- Only certain value types: string, number, boolean, null, object, array, no functions, no comments.
- Special characters must be escaped inside strings (a quote becomes
\").
Reading a JSON error
When JSON fails to parse, the error usually points to a position: “Unexpected token at line 12” or “position 340”. That location is where the parser gave up, which is often just after the real mistake, a missing comma on line 11 shows up as an error on line 12. Read the message, jump to the line, and check the lines just before it. The most frequent culprits are a missing or extra comma, an unclosed bracket or brace, and an unescaped quote inside a string.
Format (prettify) versus minify
The same JSON can be written two ways for two purposes:
| Style | Use it for |
|---|---|
| Prettified (indented) | Reading, editing and debugging, easy for humans to scan |
| Minified (single line) | Production and transport, smallest size, fewer bytes to send |
Both are functionally identical; the difference is only whitespace. Prettify while you work, minify what you ship. Being able to switch between the two on demand is most of what a JSON tool is for.
JSON and schema markup
For SEO specifically, JSON matters because JSON-LD, Google’s recommended format for schema markup, is JSON. When your Product or FAQ schema does not work, the cause is very often invalid JSON: a stray comma or an unescaped quote in a description. Because search engines silently ignore broken structured data, a JSON error in your schema fails invisibly, you get no rich result and no obvious reason why. Validating the JSON is the first debugging step whenever schema is not working.
Why JSON has no comments
A frequent surprise for newcomers: standard JSON does not allow comments. There is no // or /* */, and adding one makes the document invalid. This is deliberate, JSON was designed as a pure data-interchange format, not a config language, so it stays minimal and unambiguous. If you need comments, you are usually working with a config file, and some tools accept relaxed variants like JSONC or JSON5 that permit comments and trailing commas. But those are not standard JSON, and anything sent over an API or used as JSON-LD schema must be strict, comment-free JSON. If a parser rejects your file, a stray comment is a candidate to check alongside the usual trailing-comma culprit.
Format and validate JSON instantly
Do not hunt for a misplaced comma by eye. Paste your JSON into our free JSON formatter and validator: it prettifies or minifies the JSON, and if it is invalid, it tells you exactly where and why, so you can fix the error in seconds. It runs in your browser, so it is safe for private data. For the specific job of building valid structured data, our schema markup generator produces correct JSON-LD you will not have to debug in the first place.
The takeaway
JSON is strict, double-quoted keys, no trailing commas, escaped strings, so a single slip breaks the whole document, and error messages point to where parsing failed, usually just after the real mistake. Prettify to read and edit, minify to ship, and always validate JSON-LD before relying on it for schema. Format and check yours with the JSON formatter and validator, and explore the rest of our free SEO tools.