JSON

A simple text format for structured data made of keys, values, lists and nested objects.

In more detail

JSON stands for JavaScript Object Notation, though almost every language reads and writes it. Values can be strings, numbers, true or false, null, lists in square brackets and objects in curly braces, and keys and strings must use double quotes.

Examples

Every Ansible module reports its result as JSON, and a dynamic inventory script must print JSON in a known shape.
In the APIs course: JSON stands for JavaScript Object Notation, and it is the default format of most web APIs, including the course service.
{"id": 1, "title": "Design", "state": "open", "owner": "alice"}
{"type": "order", "id": 42, "total": 99}
Design token files in the DTCG format and every package.json are JSON.
The good variant in the course lab writes each log event as one JSON object per line on standard output, so the platform can parse it by field.
In the browser: JSON stands for JavaScript Object Notation, though every language reads it. docker inspect prints JSON, image manifests and configurations are JSON, and the exec form of CMD is a JSON array, which is why it needs double quotes.
JSON.parse(body) returns untyped data until a schema checks it.
{"name":"api","healthy":true}
{"status":"ready","count":2}
Route Handler: return Response.json({ status: 'ok' });
{"name": "Ana", "scores": [9, 7]}
CloudTrail records and STIX objects are JSON; extract their fields by walking the parsed structure, not with a regular expression.
PostgreSQL stores parsed JSON documents in JSONB columns.
In Terraform: Terraform uses it widely: jsonencode turns values into JSON text, terraform output -json and terraform show -json produce it for programs, and configuration itself can be written as .tf.json files. Pipelines and policy tools read Terraform's JSON output rather than the human format.
In this course: Most web APIs send JSON, and contracts between services describe which JSON fields a consumer relies on. Python's json module converts between JSON text and dictionaries and lists.
const raw: unknown = JSON.parse(text); // JSON.parse is typed any, so store the result as unknown and validate it
JSON.stringify leaves out keys whose value is undefined

Related terms

Taught in

References

Certification courses