JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Originally derived from JavaScript object literals by Douglas Crockford in the early 2000s, JSON has become the de facto standard for data exchange on the web. Nearly every modern API returns JSON, and it's the native configuration format for many tools and frameworks.
JSON's appeal lies in its simplicity. It uses a minimal set of syntax rules that map directly to common data structures — objects (key-value pairs), arrays (ordered lists), strings, numbers, booleans, and null. Most programming languages can parse and generate JSON with built-in libraries or a single dependency.
Unlike XML, JSON has no schema requirement, no namespaces, no processing instructions, and no closing tags. A valid JSON document can be as simple as a single value or as complex as a deeply nested structure with thousands of keys. The official specification is RFC 8259, which is only 15 pages long.
JSON has a small but strict set of rules. Violating any of these makes the document invalid:
{}. Keys must be strings enclosed in double quotes. Values can be any JSON type.[]. Elements can be of mixed types.\n, \t, \\, \", and \uXXXX for Unicode code points.0 itself). Supports e/E notation for scientific notation. No hexadecimal or octal literals.true and false (lowercase only).null (lowercase only) representing an empty or absent value.Common mistakes include trailing commas (invalid in JSON but common in JavaScript), unquoted keys, single-quoted strings, and comments (JSON does not support comments, though JSONC — JSON with Comments — is used by some tooling like TypeScript's tsconfig.json).
Validating JSON is straightforward because the format is so constrained. Most JSON parsers will throw an error with a position indicator when they encounter invalid syntax. Key things to validate:
JSON.parse() in JavaScript, json_decode() in PHP, or json.loads() in Python.eval() — it can execute arbitrary JavaScript. Always use a proper parser. Be cautious of very large JSON payloads that could exhaust memory (JSON bombing).When debugging malformed JSON, a common technique is to run it through a formatter or linter. Many editors highlight JSON errors in real-time, and online validators can pinpoint the exact character where parsing fails.
JSON is the backbone of modern data exchange. Typical applications include:
application/json).package.json, tsconfig.json, eslintrc.json, and many other tools use JSON for configuration. Some support JSON5 or JSONC for added flexibility.localStorage and sessionStorage in browsers serialize data as JSON strings.Each format has strengths depending on the use case:
The practical rule of thumb: use JSON for APIs and data exchange, YAML for human-edited configuration files, and XML only when you specifically need its features (namespaces, mixed content, or existing tooling).