Lists are used to represent an ordered collection of items. Lists are written using a hyphen “-” followed by a space, and each item in the list is separated by a new line. Here is an example of a YAML list:
fruits: - apple - banana - cherry
In this example, “fruits” is the key and the list contains three items: “apple”, “banana”, and “cherry”. The items are each written on a new line and indented by two spaces.
Lists can also contain items of different types, such as strings, numbers, and booleans. Here is an example of a mixed-type list:
items: - apple - 123 - true
In this example, the list contains a string, an integer, and a boolean value.
Lists can also be nested within other data structures, such as dictionaries. Here is an example of a nested list:
people: - name: John age: 30 hobbies: - reading - hiking - name: Jane age: 25 hobbies: - cooking - painting
In this example, the “people” key is associated with a list of two dictionaries, each representing a person. The “hobbies” key in each dictionary is associated with a nested list of hobbies.
Follow us on social media