Organizing Information Like a Pro
- How indentation creates nested groups — like folders within folders
- The 2-space rule and why tabs are forbidden
- How to read and write any nested YAML structure
Great job! You have learned the basics of YAML. Now we will learn how to organize more complex information. Think of this lesson as learning how to organize a big filing cabinet instead of just a simple folder.
Groups Within Groups (Nested Information)
Sometimes you need to organize information into groups, and then have smaller groups inside those groups. In YAML, this is super easy!
Imagine you have six settings for a chip. If you just write them all flat, it is hard to tell which ones go together. Watch what happens when we organize them into groups:
From Flat to Organized
Watch six scattered settings get sorted into two groups — processor and memory
How to Create Nesting
Here is the book’s example — a simple computer chip with two sections (processor and memory) inside one main group. Each dot (·) represents one space of indentation:
Notice how we have groups (processor and memory) inside the main group (my_chip). Each group has its own information that belongs together.
The dots make the indentation visible:
- 0 dots = top level (
my_chip:) - 2 dots = first level inside my_chip (
name,processor,memory) - 4 dots = second level inside processor or memory (
speed,cores,size)
Here is how you create this step by step:
- Write the main group name followed by a colon and nothing else:
my_chip: - On the next line, indent 2 spaces and write child items:
name: "Learning Chip" - To create a sub-group, write a label with nothing after the colon:
processor: - Items inside the sub-group get 4 spaces (2 more):
speed: 100
The rule is always the same: no value after the colon means “look below me for my contents.”
How Indentation Creates Structure
The number of spaces at the start of a line tells YAML who belongs to whom. Click Next to build a nested structure step by step — watch the tree on the right grow as each line is added:
Interactive: Indentation = Nesting
Click Next to build a YAML structure — watch the tree grow on the right
Think of it like this family tree:
- chip_design (grandparent — 0 spaces)
- name (child — 2 spaces)
- speed (child — 2 spaces)
- details (child — 2 spaces)
- size (grandchild — 4 spaces)
- power (grandchild — 4 spaces)
The rules are simple:
- Same indent = same level (siblings sitting next to each other)
- More indent = one level deeper (a child inside a parent)
- Always use 2 spaces per level. Never mix tabs and spaces
- No value after the colon = “my contents are below me”
A Real Example: Chip Specifications
Here is a real example using only nesting — no lists yet. A chip has multiple groups of settings, and each group contains its own key-value pairs:
Interactive: The Backpack Analogy
Click each pocket to open it — see the YAML that lives inside
Let’s break down the structure:
- Main container (
usb_controller): This holds everything - Information groups:
chip_info,capabilities,specifications - Individual items: Each group contains specific pieces of information
- Different data types: We used text, numbers, and true/false
Think of it like organizing your backpack:
- Backpack =
usb_controller(the main container) - Pockets =
chip_info,capabilities, etc. (the groups) - Items in pockets =
name,voltage, etc. (the individual pieces of information)
Common Beginner Questions
Key takeaways
You have learned how to organize complex information in YAML:
- ✓ Nested groups: Put related information together using indentation
- ✓ No value after the colon means “look below me for my contents”
- ✓ Same indent = siblings, more indent = children
- ✓ Always use 2 spaces per level, never tabs
- ✓ Think of it like folders inside folders or drawers in a filing cabinet
In the next lesson, we will learn how to make lists — another way to organize multiple items.