Topic 16

The Whole Grammar in One Page

Data

Every answer this book has shown you arrived in the same costume: braces, brackets, quotes, colons. That costume is JSON — JavaScript Object Notation, though nobody spells it out — and it looks like code, which is exactly the misunderstanding this page removes. JSON is not code. It is data written down: facts in text form, with strict rules about the punctuation. Nothing in it runs, loops, or decides.

Here is the claim that makes this chapter short: JSON's entire grammar is six kinds of value. Learn them on this page and there is no JSON anywhere — Tandem's, your bank's, any API on earth — that you cannot read. Think of a structured luggage tag: name, office, bags: 2. The tag describes; it never acts. JSON is luggage tags for data, nestable.

The specimen for this whole chapter: one station
{
  "id": "st_014",
  "name": "Old Market",
  "capacity": 24,
  "free_bikes": 9,
  "status": "active",
  "location": {"lat": 47.21, "lon": 8.55}
}

Objects: Labelled Facts

Curly braces { } hold an object: a set of facts, each with a label. Inside, every entry is a pair — a name in double quotes, a colon, a value: "capacity": 24. The station specimen is one object: facts about one station. Order does not matter in an object; you find things by label, not by position, exactly like reading a form.

Arrays: Ordered Lists

Square brackets [ ] hold an array: values in order, without labels. When you fetched /v1/stations in Chapter 3, the fifty stations arrived as an array of objects — a list of luggage tags. In an array, position is the only address: first, second, third. Objects answer "what is this thing's capacity?"; arrays answer "what is the third one?"

The Four Leaf Values

Everything else in JSON is one of four simple values. Strings — text in double quotes: "Old Market". Numbers — bare digits: 24, 47.21. Booleans — the two bare words true and false. And null — a bare word meaning "deliberately nothing." That is the complete inventory: objects and arrays to give structure, four kinds of leaf to carry the facts. There is no fifth thing waiting in an advanced chapter. This is all of JSON.

The specimen as a tree — every value is one of six kinds
{ } the station object
six labelled facts about Old Market
A string
"name": "Old Market" — text in double quotes
A number
"capacity": 24 — bare digits
An object inside the object
"location": { } — a fact with parts
Two numbers
"lat": 47.21 · "lon": 8.55 — grouped where they belong

Zero, Null, and Missing Are Three Different Answers

One distinction earns its own section because it bites in real data. "free_bikes": 0 says: counted, and there are none — an empty station. "free_bikes": null says: this field exists but deliberately holds nothing — perhaps the station is offline and the count is unknown. And no free_bikes key at all says: this response simply does not carry that fact. Three different statements. A report that treats them as the same will lie to the city about which stations are empty versus which are unreported — the kind of quiet error the Thursday report cannot afford.

Common Confusions
  • "JSON is a programming language." It is notation — data in text form. Nothing in it executes. Reading JSON is exactly as dangerous as reading a luggage tag.
  • "The quotes and commas are flexible style." The grammar is strict: double quotes only, commas between entries and never after the last. That strictness is why every tool on earth reads JSON identically.
  • "null, 0, and a missing field all mean the same nothing." Counted-as-zero, deliberately-unknown, and not-carried are three different statements — and real reports go wrong by merging them.
  • "I need to learn JavaScript because JSON comes from it." The name is a historical accident. JSON left home long ago; every language reads it, and you need none of them.
Why It Matters
  • Nearly every API you will ever meet speaks JSON. This one page is the literacy the entire rest of the shelf assumes — six kinds of value, and you have them.
  • Knowing JSON cannot execute removes a real fear: opening, reading, and pretty-printing any response, from anyone, is always safe. Curiosity is free here.

Knowledge Check

What is the complete inventory of JSON's value kinds?

  • Objects and arrays for structure, with strings, numbers, booleans, and null
  • Objects, arrays, strings, numbers, dates, and functions for computed fields
  • Text, integers, decimals, lists, tables, and computed formulas
  • Rows, columns, cells, headers, values, and category labels

What is the difference between an object and an array?

  • Objects hold text values, while arrays are reserved for numeric values
  • Objects hold labelled facts found by name; arrays hold values found by position
  • Objects are meant for small data and arrays are meant for large data
  • Objects appear mostly in responses and arrays appear mostly in requests

A station's data shows "free_bikes": null. What is it saying?

  • The station was counted just a moment ago and currently has zero bikes available to rent
  • The response arrived corrupted and the field's value failed to transmit
  • The field is present and deliberately empty, with the count unknown right now
  • This response simply does not include bike counts for any station

You got correct