Development guide

JSON Formatting and Validation: How to Find Errors Without Guessing

Learn the difference between formatting and validation, diagnose common JSON syntax errors, and verify data before using it in an API or application.

ToolsDiary Editorial Team 4 min read Updated September 7, 2026
01

Formatting and validation solve different problems

JSON formatting makes structured data easier for a person to read by adding indentation and consistent line breaks. Validation answers a different question: whether the text follows JSON syntax closely enough to be parsed as data. A document can be beautifully formatted and still be invalid if it contains a missing comma, an extra trailing comma, an unquoted property name or an unfinished string. Conversely, compact JSON on one long line can be completely valid. Treat formatting as a readability step and validation as a correctness check. When debugging an API request, configuration file or copied payload, validate first, then format the valid structure so the remaining data-level problems are easier to inspect.

02

Start with the first syntax error, not the last symptom

Parsers usually stop near the first place where the grammar no longer makes sense. A missing quote near the top of a document can make later braces, commas and values appear wrong even when those later characters are fine. That is why fixing every highlighted line at once is inefficient. Read the first reported error, inspect the characters immediately before it, make one correction and validate again. Common causes include a comma missing between properties, a closing bracket paired with the wrong opening character, text placed outside the top-level object or array, and a string that contains an unescaped quotation mark. Solving the earliest structural problem often removes several later errors automatically.

03

Objects, arrays and values have strict boundaries

A JSON object uses curly braces and contains name-value pairs. Property names must be strings inside double quotation marks. An array uses square brackets and stores ordered values. Values can be strings, numbers, true, false, null, objects or arrays. JSON does not allow JavaScript comments, functions, undefined, single-quoted strings or bare identifiers. This distinction matters when copying data from JavaScript examples because JavaScript object literals are more flexible than JSON. If a configuration snippet uses comments or single quotes, it may be valid JavaScript but invalid JSON. Converting it safely means understanding the structure rather than simply replacing every quote character.

04

Trailing commas are a frequent copy-and-paste problem

Many programming languages and configuration formats tolerate a comma after the final item in a list. Standard JSON does not. In an object, the last property must not end with a comma before the closing brace; the same rule applies to the last value in an array. This error is easy to create when a developer deletes the final property but leaves the separator behind. It is also easy to miss in a long minified payload. A formatter can expose the location visually, while a validator confirms whether the comma is actually illegal in the JSON being checked. Avoid automatically removing every comma because commas between items are required.

05

Escaping keeps special characters inside strings

Double quotes mark the beginning and end of a JSON string, so a literal quote inside the value must be escaped. Backslashes also have special meaning. New lines, tabs and some control characters use escape sequences rather than being pasted as raw control characters. A common example is a sentence containing quotation marks: the inner marks need a backslash so the parser does not think the string ended early. URLs normally do not need their forward slashes escaped, even though some software chooses to display them that way. When a JSON string contains code, regular expressions or Windows file paths, inspect backslashes carefully because multiple layers of escaping can make a visually plausible value invalid.

06

Syntax validation does not prove the data is correct

A validator can confirm that a payload is valid JSON while the application still rejects it. Syntax rules do not know whether an email field contains a real address, whether an order total should be positive, whether a required property is missing or whether an API expects an integer instead of a string. Those requirements belong to a schema or to the receiving application's business rules. After syntax passes, compare the property names, value types and required fields with the documentation for the system that will consume the data. This two-stage approach prevents developers from confusing a clean parse with a correct request.

07

Use a repeatable debugging workflow

Keep an untouched copy of the original payload, especially when debugging production data. Paste a working copy into a JSON formatter and validator, fix the first syntax problem, and repeat until the parser accepts it. Then collapse or format the document as needed and compare its fields with the API, import or configuration specification. For large payloads, isolate the smallest object or array that reproduces the problem rather than editing thousands of lines at once. ToolsDiary's JSON Formatter and Validator can help with syntax and readability, but it cannot know the private business rules of the application receiving the JSON.

Questions readers ask

Frequently asked questions

Is formatted JSON automatically valid?

No. Indentation only improves readability. Invalid commas, quotes, brackets or value syntax can remain in a formatted document.

Why does JSON reject single quotes?

The JSON specification requires double quotation marks for strings and property names. Single quotes may work in JavaScript source code but are not standard JSON.

Can JSON contain comments?

Standard JSON has no comment syntax. If comments are required, use a format or parser that explicitly supports them rather than assuming ordinary JSON will accept them.

What is the difference between JSON validation and JSON Schema?

Syntax validation checks whether the text is legal JSON. A schema can additionally describe required fields, allowed types, ranges and structural rules for a particular data model.

Should I send private API data to an online formatter?

Avoid exposing secrets, tokens or confidential production data unnecessarily. Prefer local processing for sensitive payloads and remove credentials before sharing diagnostic examples.

Editorial note

This guide is informational and is reviewed against the public behavior of the tools described. See our editorial policy.