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 created by Douglas Crockford in 2001, who described the format at json.org after using it with Chip Morningstar at State Software. It was later formalised independently by Ecma International (ECMA-404) and the IETF (RFC 8259, linked above), which is why you'll see both cited as the JSON spec. Despite its JavaScript origins, JSON 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, IEEE 754 double. 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.
Numbers are unbounded in the spec, but most parsers store them as IEEE 754 double-precision floats, including JavaScript's Number type. That's exact for integers only up to 253. See JSON best practices for how to handle IDs larger than that.
Nesting objects and arrays
Any JSON value can contain any other JSON value, so objects and arrays nest freely to whatever depth you need — the only real limit is your parser's call stack. A typical API response combines several layers: an object holding a nested object, plus an array of objects.
{ "id": 1024, "customer": { "name": "Alice", "vip": true }, "items": [ { "sku": "A1", "qty": 2 }, { "sku": "B7", "qty": 1 } ] }
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))This site's JSON Formatter validates and beautifies any JSON document instantly, without leaving the browser.
Try it now
Frequently asked questions
JSON (JavaScript Object Notation) was inspired by JavaScript object literal syntax, but it is an independent, language-agnostic format defined by RFC 8259.
Every major programming language has JSON support built in or available via a standard library: Python (json module), Java (Jackson, Gson), PHP (json_encode/json_decode), Go (encoding/json), Rust (serde_json), and so on.