💻 Text & Dev
📋 📋 JSON Formatter & Validator: How JSON Works
Learn how JSON works, the rules for valid JSON, and how to format and validate it. Covers data types, nesting, common syntax errors, JSON vs XML, and using JSON in REST APIs.
⏱️ 8 min read🦉 365tool.net🌍 For everyone worldwide
JSON (JavaScript Object Notation) is the dominant data interchange format on the web. Every major API, configuration file ecosystem, and web application uses it. It replaced XML for most use cases because it is lighter, more readable, and maps directly to data structures in every modern programming language.
JSON Data Types
JSON supports exactly six types:
- String:
"hello" — always double quotes
- Number:
42, 3.14, -7, 1.5e10
- Boolean:
true or false — lowercase
- Null:
null — lowercase
- Object:
{"key": "value"} — keys must be strings
- Array:
[1, "two", true, null]
JSON Syntax Rules
{
"name": "Alice",
"age": 30,
"isActive": true,
"score": null,
"tags": ["admin", "user"],
"address": {"city": "London"}
}
- Keys must be double-quoted strings:
{"name": "x"} ✅ / {name: "x"} ❌
- Strings use double quotes only:
"hello" ✅ / 'hello' ❌
- No trailing commas:
{"a":1, "b":2} ✅ / {"a":1, "b":2,} ❌
- No comments: JSON has no comment syntax
- Lowercase booleans and null:
true ✅ / True ❌
Most Common JSON Errors
| Error |
Invalid |
Valid |
| Single quotes | {'key': 'val'} | {"key": "val"} |
| Trailing comma | {"a":1, "b":2,} | {"a":1, "b":2} |
| Unquoted key | {name: "Alice"} | {"name": "Alice"} |
| Python boolean | {"active": True} | {"active": true} |
Pretty-Print vs Minified JSON
Pretty-printed: indentation and newlines for readability. Minified: whitespace stripped for smaller file size — {"name":"Alice","age":30}. At high-volume APIs, minification meaningfully reduces bandwidth.
JSON vs XML
| Feature |
JSON |
XML |
| Verbosity | Compact | Verbose |
| Native arrays | Yes | Workaround |
| Comments | Not supported | Supported |
| Primary use | Web APIs, configs | Enterprise, documents |
❓ Frequently Asked Questions
What are the rules for valid JSON?▼
Keys must be double-quoted strings. String values use double quotes (never single). No trailing commas after the last item. No comments. Booleans are true/false (lowercase). Null is null. Numbers need no quotes. The root element must be an object {} or array [].
Why does my JSON show an error?▼
Most common JSON errors: single quotes instead of double quotes, trailing comma after the last item, unquoted keys, comments (JSON has no comment syntax), and Python-style True/False/None instead of true/false/null. A formatter highlights the exact line causing the error.
What is the difference between pretty-printed and minified JSON?▼
Pretty-printed JSON has indentation and newlines for readability. Minified removes all whitespace for smaller size. For APIs serving millions of requests, minification reduces bandwidth meaningfully. Use pretty-print for debugging; minify for production.
What are JSON data types?▼
JSON has six types: string ("hello"), number (42, 3.14), boolean (true or false), null, object ({"key": "value"}), and array ([1, "two"]). There is no date type (use ISO 8601 strings), no undefined, no functions, and no special values like NaN.
When should I use JSON vs XML?▼
Use JSON for web APIs, configuration files, and modern applications. JSON is more compact, readable, and natively supported everywhere. Use XML when you need document-like features, mature schema validation (XSD), or interoperability with legacy enterprise systems.