liveBook · Manning

Name-value pair

As explained in Everyday Data Visualization

A key-value pair is a named data association in which a key identifies and a value supplies the associated data.

A name-value pair, usually called a key-value pair, connects an identifying key on the left with its associated data on the right. In JSON, the key comes first, followed by a colon and the value; commas separate pairs inside an object. section 3.5.2

A JSON key-value pair has a small but useful vocabulary:

  • Keys must be strings enclosed in double quotation marks. section 3.5.2
  • Values may be strings, numbers, Booleans, arrays, objects, or null. section 3.5.2
  • Nesting pairs inside objects makes related data easier to name, although deeper structures can become harder to read. section 3.5.2

Fruit taste scores

An object can pair each fruit name with a numerical taste score: “Bananas” maps to 80, while “Oranges” maps to 50. A more elaborate structure can instead use an index as the outer key and nest fruit and taste-score pairs inside it. section 3.5.2

{
   "Fuyu Persimmons": 100,
   "Mangos": 100,
   "Peaches + Nectarines": 100,
   "Bananas": 80,
   "Kiwis": 70,
   "Apples": 60,
   "Oranges": 50
} 

Inspect a compact object whose seven key-value pairs connect fruit names with taste scores. section 3.5.2

How Everyday Data Visualization covers it

How deep it goes
Defines syntax, key and value types, nesting, and alternative organizations, but does not detail programmatic generation.
Examples
Uses weekday schedules, fruit taste scores, indexed fruit records, and a titled nested fruit dataset.
What it assumes
Builds from basic data types and data structures before introducing nested objects and key-value pairs.
What you can do after
Apply via JSON by structuring named values, nesting related records, and preparing simple visualization data.
How it connects
Connects key-value pairs to JSON, objects, arrays, nested data, and data visualization.

Also explained in

Compare how 11 books explain name-value pair →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Everyday Data Visualization. The section links point to the parts of the book it draws on.