Should we find a value by its name or its place?
02Move named drawers and reorder a queue to see why objects and arrays mean different things.
A named drawer answers “Which value is called pet?” A queue answers “Which value is first?”
Drawers have names
What happens if you change this?
Make one change, then watch again. Restart restores the original example.
Two members named role can produce different results in different implementations.
Key idea: Use unique names to find named values; use an array when order matters.
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
Use unique names for members and positions for ordered elements.
- Object names are strings; a colon separates name and value, and commas separate members. Names should be unique.
- An array is ordered, can be empty, and may mix value types.
- Applications that depend on object-member order are less interoperable because parsers expose that order differently.
Duplicate object names can be accepted by the grammar but produce incompatible consumer behavior: last value, all values, or an error. Use unique names to avoid this ambiguity.
RFC 8259 §4 recommends unique names (SHOULD), rather than making duplicates a grammar error. Object member ordering may be exposed differently. §5 arrays are ordered and may mix value types. The three duplicate-reader outputs shown are examples, not one mandated policy.
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.