Here are several examples of YAML lists to illustrate how they can be structured in different contexts:
1. Simple List
A basic list of items:
fruits:
- apple
- banana
- orange
2. List of Dictionaries
A list where each item is a dictionary (key-value pairs):
employees:
- name: John Doe
position: Developer
- name: Jane Smith
position: Manager
3. List of Lists
A list that contains other lists:
matrix:
- [1, 2, 3]
- [4, 5, 6]
- [7, 8, 9]
4. List with Mixed Types
A list that contains different types of data:
mixedList:
- 42
- "Hello, World!"
- true
- null
5. Nested Lists
A more complex structure with nested lists:
projects:
- name: Project A
tasks:
- task: Design
status: completed
- task: Development
status: in-progress
- name: Project B
tasks:
- task: Testing
status: pending
6. List with Comments
You can also include comments in YAML:
colors:
- red # Primary color
- green # Secondary color
- blue # Primary color
Summary
YAML lists can be simple or complex, containing various data types and structures. They are defined using dashes (-) to denote each item, making it easy to represent collections of data in a clear and organized manner. If you have further questions or need more examples, feel free to ask!
