Use this when writing YAML key-value mappings.
Mappings
YAML mappings are key-value pairs written key: value, nested by indentation with spaces, never tabs. They correspond to JSON objects and Python dictionaries.
1. Mappings are key: value pairs.
2. Duplicate keys are errors (some parsers keep the last one silently).
3. Indentation defines nesting.
4. Quote special keys.
5. Order not significant.
key: value → mapping
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to key/value uniqueness, scalar typing, merge/anchor effects and deterministic mapping into the consumer schema.
Step 2 Common mistakes Narrow the fault
- Tabs instead of spaces.
- Duplicate keys silently overwriting.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Mappings are key: value pairs.
- Nesting uses indentation with spaces.
- Duplicate keys are errors or silently overwrite.
yq 'keys' file.yaml— mapping keysyamllint -d '{rules: {key-duplicates: enable}}' file.yaml— duplicate keys- Indentation consistency — structure
ReferenceWhy it matters1 section · depth on demand
What it is
A YAML mapping is a set of key: value pairs, nested by indentation.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
A YAML mapping is a set of key/value pairs — the YAML equivalent of a JSON object or Python dict. Nesting is expressed with indentation (spaces only, consistently, usually two).
interface:
name: GigabitEthernet1/0/1
description: "Printer, floor 2"
access_vlan: 20
Keys must be unique within a mapping; many parsers silently keep only the last duplicate, which hides mistakes — yamllint reports duplicates. Quote keys or values that contain :, #, or start with special characters (*, &, !, {, [).
Mechanics
The linked authority for bounded mechanics is YAML 1.2.2 Specification; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in YAML > Mappings. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://yaml.org/spec/1.2.2/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For key/value uniqueness, scalar typing, merge/anchor effects and deterministic mapping into the consumer schema, prefer typed fields and stable IDs over human presentation text.