← BlogThe Complete JSON Guide
JSON (JavaScript Object Notation) is the most popular data format on the internet today. From API responses to configuration files, from database storage to frontend rendering — JSON is everywhere. This guide takes you from zero to mastery.
Part 1: What Is JSON?
JSON is a lightweight text data interchange format. Based on a subset of JavaScript syntax but language-independent — any language can parse and generate JSON. Its core advantages: human-readable, machine-parseable, compact.
Part 2: Basic Syntax
JSON has only two structures: objects and arrays.
- Keys must be wrapped in double quotes
- String values must use double quotes
- Numbers, booleans (true/false), and null don't need quotes
- Items separated by commas
- No trailing commas allowed
- No comments supported in the JSON standard
Part 3: Data Types
- string — "hello", "北京"
- number — 42, 3.14, -10 (no distinction between int and float)
- boolean — true, false
- null — null
- object — {} key-value pairs
- array — [] ordered list of values
Part 4: Nesting & Complex Structures
JSON's real power is nesting. A user object can contain an array of addresses, each address being its own object with coordinates — the possibilities are limitless.
Part 5: JSON in APIs
Almost all modern APIs use JSON. A typical response includes status, data payload, and metadata — all in a single, parseable structure.
Part 6: Common Errors
- Trailing commas — the most common error. Trailing commas before closing braces or brackets are illegal
- Single quotes — JSON requires double quotes for keys and strings
- Missing commas — items must be separated by commas
- Comments — JSON does not support line or block comments
- Unquoted keys — {name: "Alice"} is illegal; must be {"name": "Alice"}
Part 7: JSON vs XML vs YAML
- JSON — lightest, API default, no comments
- XML — supports attributes and namespaces, enterprise systems, has Schema validation
- YAML — most human-readable, great for config files, but parsing can be tricky