JSON (JavaScript Object Notation) is the text format almost every modern API uses to send data — and the format nearly every AI tool reads and writes. Prompts, tool calls, and function arguments are all JSON. It is just text, structured by a handful of simple rules, so any program (and any human) can read it.
The six value types
- string — text in double quotes: "hello". Double quotes only, never single.
- number — 42, -3.14, 1.5e3. No quotes, no thousands separators, no leading zeros.
- boolean — true or false (lowercase, no quotes).
- null — the explicit "no value here".
- object — a collection of key/value pairs (below).
- array — an ordered list of values (below).
Objects — labelled data
An object is wrapped in curly braces { } and holds key: value pairs separated by commas. Keys are always strings in double quotes; values can be any of the six types. Order does not matter — you look values up by key, not by position.
{
"id": 42,
"name": "Acme Corp",
"active": true,
"balance": 1500.50,
"notes": null
}Arrays — ordered lists
An array is wrapped in square brackets [ ] and holds an ordered list of values separated by commas. You access items by position, counting from 0. The items are usually all the same shape (a list of records), but JSON does not require it.
["red", "green", "blue"]
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]Nesting — the part that trips people up
Values can contain other objects and arrays, to any depth. This is how APIs represent real-world structure — an order that contains a customer object and a list of line-item objects. Reading nested JSON is just following the path: an object key with a dot, an array item with an index.
{
"orderId": "A-1001",
"customer": { "name": "Alice", "city": "Jaipur" },
"items": [
{ "sku": "PEN", "qty": 3 },
{ "sku": "PAD", "qty": 1 }
]
}
// customer.name -> "Alice"
// items[0].sku -> "PEN"
// items[1].qty -> 1The rules people break most
- Double quotes only — 'single' quotes and unquoted keys are JavaScript, not valid JSON.
- No trailing comma after the last item — {"a":1,} is invalid.
- No comments — JSON has no // or /* */ (the // lines above are just for this lesson).
- Keys are case-sensitive — "Name" and "name" are two different keys.
Tip · When a response "looks like garbage", paste it into a JSON formatter/validator. Most "it is not working" moments are a missing quote, a trailing comma, or reading name when the key is actually userName.
A word on XML
Before JSON won, most APIs used XML — the same information wrapped in nested tags instead of braces. Many enterprise, banking, and government systems still do. It carries the same data; it is just heavier and uses <tags> and attributes instead of keys.
<order id="A-1001">
<customer>
<name>Alice</name>
<city>Jaipur</city>
</customer>
<items>
<item sku="PEN" qty="3"/>
</items>
</order>- JSON is lighter, maps directly to objects and arrays, and is the default for new APIs.
- XML supports attributes, namespaces, and schemas (XSD) — still common in SOAP, e-invoicing, and older enterprise APIs.
- You will occasionally meet both; the skill is identical — understand the structure, then pull out the fields you need.
Tip · Getting fluent at reading JSON is the single highest-leverage skill in this course — every API response, and every AI tool call, is JSON underneath.