Tree · Beginner · Step-through

YAML: How to Read the Structure

Each row pairs a small YAML example with the tree YAML builds from it. Press Next to highlight one idea at a time; the code itself never changes.

YAML: How to Read the Structure Five YAML examples shown beside the trees they produce: a key and value split by a colon, a dictionary whose indented fields belong to person, a list whose hyphens start items, a list of student dictionaries, and how indentation with spaces marks levels and children. CONCEPT YAML CODE · NEVER CHANGES TREE · HOW YAML READS IT 1 name: Ram KEY VALUE ↑ COLON COLON KEY name VALUE Ram STEP 01 Key and value The colon separates the key from its value. Read it as: “name is Ram”. 1 person: 2 name: Ram 3 age: 30 DICT person name: Ram age: 30 STEP 02 Dictionary A key with nothing after its colon opens a group. The indented lines below it — name and age — belong to person. 1 tools: 2 - Docker 3 - Kubernetes LIST tools ITEM 1 Docker ITEM 2 Kubernetes STEP 03 List Each hyphen starts another list item. tools holds two items: Docker and Kubernetes. 0 2 4 ← SPACES OF INDENT 1 students: 2 - name: Ram 3 age: 20 4 - name: Sita 5 age: 22 LEVEL 0 · 0 SPACES LEVEL 1 · 2 SPACES LEVEL 2 · 4 SPACES LIST students ITEM 1 student 1 ITEM 2 student 2 name: Ram age: 20 name: Sita age: 22 STEP 04 List of dictionaries Each hyphen starts a new student. The name and age written under that hyphen are nested inside that one student. 1 person: ·· 2 name: Ram ⇥ name: Ram ✗ ✓ 2 SPACES ✗ TAB Same spaces = same level name and age both start 4 spaces in, so they are siblings inside one student. More spaces = child A line indented further than the line above it belongs to that line. STEP 05 Indentation Fields with the same spaces are at the same level. Child fields use more spaces than their parent. Indent with spaces, never tabs. MEMORY RULE Colon gives a value. Hyphen starts a list item. Indentation shows what belongs together. LEGEND Parent: dictionary, list, or list item Leaf: a single value Current step (during playback) KEY · DICT · LIST · ITEM tags name the role
←/→ step · Space play/pause · R replay · Home/End jump