Home › Other › JSON

JSON

JSON is how programs hand structured data to each other. It is small, human-readable, and supported everywhere.

JSON (JavaScript Object Notation) is a text format for structured data. It grew out of JavaScript but is now language-neutral — every major language can read and write it, which is why APIs speak it.

What it looks like

{
  "id": 42,
  "name": "Ada",
  "active": true,
  "roles": ["admin", "editor"],
  "profile": {
    "city": "London",
    "age": null
  }
}

The whole type system

JSON has just six value types, and that is the point — it is deliberately tiny:

Parsing and producing it

// JavaScript
const obj = JSON.parse(text);        // text  -> value
const text = JSON.stringify(obj);    // value -> text
JSON.stringify(obj, null, 2);        // pretty-printed
# Python
import json
obj  = json.loads(text)
text = json.dumps(obj, indent=2)

Rules that trip people up

Related: YAML and TOML are friendlier for config files (they allow comments), but for machine-to-machine data over the wire, JSON is the default.

Keep reading