How can another app read our shopping list?
01Group familiar values, write their relationships as text, and let a reader rebuild the information.
The picture groups values. A container can hold more values; a word, number, true, false or null can also stand alone.
The information we want to send
- buyOrdered list [ ]
- Place 1
"apple"text - Place 2
"pear"text
- Place 1
- paid
falseyes/no value
What happens if you change this?
Make one change, then watch again. Restart restores the original example.
Strings, numbers, booleans, and null terminate branches of the tree.
Key idea: JSON writes one value as text, including the relationships between values inside it.
Terms
- JSON
- JavaScript Object Notation: shared rules for writing data as text. Apps in many languages use it.
- Object
- A group of named values, like drawers with different labels.
- Array
- A list whose values have meaningful positions.
- String
- A text value between quotation marks.
- Grammar
- Rules for which marks and words may appear and where.
- Interoperability
- Different apps can read the same data and agree about its meaning.
Rules & examples
JSON carries one value and its structure as text.
- Values are object, array, number, string, true, false, or null. Literal names are lowercase.
- A top-level text can be any JSON value, including a scalar.
- Only space, tab, carriage return, and line feed are insignificant JSON whitespace. Comments and trailing commas are outside the grammar.
JSON syntax is language-independent. A JavaScript expression that happens to resemble JSON can still be invalid JSON.
RFC 8259 §§2–3: any JSON value may be the root. Only SP, HTAB, LF and CR are insignificant whitespace. true, false and null are lowercase. Comments and trailing commas are not in the grammar.
Sources
New to this? Start hereA quick picture + helpful background
First, agree how to read the message.
An encoding tells a reader how to interpret bytes. A format tells it how values fit together. Correctly reading a value does not make that value trustworthy.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.