Sequences (Lists) 📋¶
YAML sequences (also known as lists) are ordered collections of values. They are used to represent data structures like arrays and lists in a simple and readable format.
Basic List¶
Sequences are defined using a dash (-
) followed by a space for each item in the list.
yml
fruits:
- 🍎 Apple
- 🍌 Banana
- 🍒 Cherry
- Each item in the list starts with a
-
- Items are indented for clarity (optional but recommended).
Nested Lists¶
You can nest lists within lists to represent more complex data structures.
yml
favorites:
- colors:
- 🔴 Red
- 🟢 Green
- 🔵 Blue
- numbers:
- 1️⃣ One
- 2️⃣ Two
- 3️⃣ Three
- The favorites key contains a list of nested lists (colors and numbers).
Lists of Dictionaries¶
Lists can contain dictionaries (mappings), which is useful for representing structured data.
yml
employees:
- name: chaitu-ycr
age: 30
department: 🛠️ Engineering
- name: ycr dummy
age: 25
department: 📈 Marketing
- Each item in the employees list is a dictionary with name, age, and department keys.
Mixed Lists¶
Lists can contain different types of items, such as strings, numbers, and booleans.
yml
mixed_list:
- "String" 📜
- 42 🔢
- true ⚖️
- null 🌀
- The mixed_list contains a string, an integer, a boolean, and a null value.
Lists with Multiline Strings¶
Lists can include multiline strings using block or folded scalars.
yml
notes:
- >
This is a folded string 📄
in a list item.
- |
This is a block string 🖋️
in a list item.
- The first item uses a folded scalar (
>
). - The second item uses a block scalar (
|
).
Combining Sequences and Mappings¶
You can combine sequences and mappings to create complex structures.
yml
complex_structure:
- name: "Item 1" 📦
attributes:
- attribute1: value1
- attribute2: value2
- name: "Item 2" 📦
attributes:
- attribute1: value3
- attribute2: value4
- Each item in complex_structure is a dictionary with a nested list of dictionaries (attributes).