Organizing Information Like a Pro

8 min read · Beginner
You will learn
  • 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

Scroll down to see the animation

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:

# My Simple Computer Chip
my_chip:
·· name: "Learning Chip"
·· designer: "Your Name"
·· # Processor section
·· processor:
···· speed: 100
···· cores: 2
···· type: "ARM"
·· # Memory section
·· memory:
···· size: 512
···· type: "DDR4"
···· speed: 2400
· = one space

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:

  1. Write the main group name followed by a colon and nothing else: my_chip:
  2. On the next line, indent 2 spaces and write child items: name: "Learning Chip"
  3. To create a sub-group, write a label with nothing after the colon: processor:
  4. 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

chip_design:
name: "My Chip"
speed: 100
details:
size: "small"
power: "low"
chip_designnamespeeddetailssizepower
Click Next to start. YAML on the left, tree structure on the right — watch how indentation creates the hierarchy.

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

usb_controller (the backpack)
i Chip Info
+ Capabilities
# Specifications
usb_controller:
  chip_info:
    name:"Simple USB Controller"
    version:"1.0"
    designer:"Student Engineer"
  capabilities:
    usb_version:"2.0"
    max_speed:480
    number_of_ports:4
    power_saving:true
  specifications:
    voltage:3.3
    frequency:48
    package_type:"BGA"
    pin_count:64

Let’s break down the structure:

  1. Main container (usb_controller): This holds everything
  2. Information groups: chip_info, capabilities, specifications
  3. Individual items: Each group contains specific pieces of information
  4. 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

Q How many spaces should I use for indentation?
Q How deep can I nest?
Q What if I make a mistake with spaces?

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.