YAML by Example: Mappings
1.2
Objects and dictionaries. Understanding key-value collections.
Code
# Block style
person:
name: John
age: 30
address:
street: 123 Main St
city: New York
# Flow style
point: { x: 10, y: 20 }
# Complex keys (using ?)
? [ red, green ]
: "colors"Explanation
Mappings are collections of key-value pairs, also called dictionaries or objects. Block style uses new lines and indentation to nest mappings. Flow style uses curly braces like JSON objects, useful for small inline structures.
While rare, YAML allows complex keys using a question mark to separate the key from its value. This lets you use sequences or mappings as keys themselves, though most use cases only need simple string keys.
Code Breakdown
3
name: John is a standard key-value pair.10
{ x: 10, y: 20 } is the inline flow syntax for objects.
