Raw JSON is unreadable; invalid JSON causes silent failures. Learn to format, validate, and debug JSON with explanations of every common JSON error and how to fix them.
JSON is everywhere — API responses, configuration files, data exports, webhook payloads, and NoSQL databases all use it. But raw JSON is often minified into a single unreadable line, or riddled with syntax errors that cause cryptic failures. An online JSON formatter and validator fixes both problems in seconds.
JSON (JavaScript Object Notation) is a lightweight data interchange format. It uses human-readable text to represent structured data as key-value pairs, arrays, and nested objects. Valid JSON looks like this:
{
"name": "Jane Smith",
"age": 34,
"roles": ["admin", "editor"],
"address": {
"city": "London",
"country": "UK"
}
}When JSON comes from an API or file export, it is often minified — all whitespace removed to reduce size: {"name":"Jane Smith","age":34,"roles":["admin","editor"]}. That is machine-readable but very difficult for humans to inspect or debug. Formatting (also called “pretty-printing”) adds indentation and line breaks, making the structure immediately readable.
{name: "Jane"} is invalid; {"name": "Jane"} is correct.{ or [ nested somewhere in complex JSON is easy to miss.\\ for a literal backslash, \" for a quote inside a string).| Option | Description | Use case |
|---|---|---|
| 2-space indent | Standard readable formatting | Code review, documentation, debugging |
| 4-space indent | Wider indentation | Personal preference, some style guides |
| Tab indent | Tabs instead of spaces | Codebases using tab indentation |
| Minified (compact) | No whitespace, single line | API payloads, file size reduction |
| Sorted keys | Object keys in alphabetical order | Consistent diffs, documentation |
Standard JSON is strict by design — no comments, no trailing commas, no unquoted keys. Some tools and config formats use relaxed variants:
If you are validating a VS Code config or similar JSONC file, the errors reported by a strict JSON validator are expected — those files are not standard JSON.
The ToolsGravity JSON Formatter is a daily tool for any developer who works with APIs, configuration files, or data pipelines. Paste your JSON, get it formatted and validated in one click, and copy the result. For JWT tokens (a specific JSON-based format), the dedicated JWT Decoder provides a more specialised view of the token's header, payload, and signature.