What is JSON?
JSON explained: data types, syntax rules, and why it became the universal data format for APIs and config files.
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. It was standardised in RFC 8259 and is now the default data format for REST APIs, configuration files, databases, and practically everything that passes data between systems.
JSON was derived from JavaScript object literal syntax in the early 2000s, but it is completely language-agnostic — every major programming language can read and write it natively.
The 6 JSON data types
JSON supports exactly six value types. Nothing else is valid.
"Hello""2024-01-31"""Always double-quoted. Single quotes are invalid.
423.14-71.5e10Integer or float. No NaN, no Infinity, no hex.
truefalseLowercase only. True and False are invalid.
nullRepresents the intentional absence of a value.
[1, 2, 3]["a", "b"][]Ordered list of any JSON values. Can be mixed types.
{"key": "val"}{}Unordered key-value pairs. Keys must be strings.
Syntax rules
JSON has a small, strict set of rules. Break any one of them and the document is invalid.
{"name": "Alice"}{name: "Alice"}"hello"'hello'{"a": 1, "b": 2}{"a": 1, "b": 2,}{"rate": 0.15}{"rate": 0.15} // VAT{"code": 7}{"code": 007}{"val": null}{"val": undefined}JSON vs XML
Before JSON, XML dominated data exchange. Here is the same data in both formats.
{ "name": "Alice", "age": 30, "admin": true, "tags": ["dev", "ops"] }
<user> <name>Alice</name> <age>30</age> <admin>true</admin> <tags> <tag>dev</tag> <tag>ops</tag> </tags> </user>
| JSON | XML | |
|---|---|---|
| Verbosity | Compact | Verbose |
| Native types | number, boolean, null, array | Strings only (attributes aside) |
| Comments | Not supported | Supported |
| Schema validation | JSON Schema | XSD, DTD |
| Human-readable | Easy | Cluttered with tags |
| Parse speed | Fast | Slower |
| Still used for | APIs, config, storage | SOAP, SVG, Office docs |
Where JSON is used
Content-Type: application/jsonpackage.json, tsconfig.json, .eslintrcdb.users.find({ active: true })localStorage.setItem("prefs", JSON.stringify(obj))Try it now