Section 2 · JSON basics

Objects, arrays, and the six value types

JSON has an astonishingly small grammar — you can learn all of it in one sitting. Everything is built from just two containers (object and array) holding six kinds of values. Let's meet them all, live.

1The object — a bag of key/value pairs

An object is wrapped in curly braces { }. Inside, you list "key": value pairs separated by commas. Keys are always double-quoted strings.

An object · edit the values
You type · JSON
Parsed result
try adding a new "color": "red" pair (mind the comma!)

2The array — an ordered list

An array is wrapped in square brackets [ ] and holds values in order, separated by commas. The items can be anything — even objects or other arrays.

Arrays · lists of anything
You type · JSON
Parsed result
arrays keep order; objects are keyed by name

3The six value types

Any value in JSON is exactly one of these. The colours below match the output panels everywhere in this site:

string · "text" number · 42 or 3.14 boolean · true / false null · "nothing" object · { } array · [ ]
TypeLooks likeNotes
String"hello"Always double quotes. Use \n, \", \\ for escapes.
Number42, -3.14, 2e3No quotes. Integer or decimal. No NaN/Infinity.
Booleantrue, falseLowercase, no quotes.
NullnullRepresents "no value". Lowercase, no quotes.
Object{ "k": v }Unordered key/value pairs.
Array[ v, v ]Ordered list of values.
All six types in one document
You type · JSON
Notice each colour
the output colours the value by type
The mental model A JSON document is a tree: objects and arrays are branches, the four simple types (string, number, boolean, null) are the leaves. Every file is one root value — usually an object.

🧠Checkpoint

🧠

Quick check

1. Which is a valid JSON string?
JSON strings must use double quotes. Single quotes and bare words are invalid.
2. [ ] creates a(n)…
Square brackets = array. Curly braces { } = object.
3. How many value types does JSON have?
Exactly six — two containers (object, array) and four leaves (string, number, boolean, null).
🔓 You're reading a free chapter of JSON & YAML — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices