Skip to content

YAML Sequences

Learn how YAML sequences work as collections (like lists or arrays) with block style (using dashes) and flow style (using square brackets), including nested sequences.

A YAML file is rarely used to describe a simple scalar. Most of the time, it describes a collection.

YAML collections can be a sequence or a mapping of elements.

In YAML, the collection is represented with proper sequence styles.

YAML Sequences

YAML sequences are the equivalent of lists, arrays, etc. of programming languages.

The individual items of a sequence can have any type (strings, integers, floating-point numbers, mappings, or sequences)

Sequences can be created in two equivalent ways:

Block Style version

Sequences can be written in block style, using one line for each item in the sequence, with each line starting with a dash (-):

menu:
-  pizza
-  pasta
-  hamburger
-  steak
-  salad

Flow Style version

Sequences can be written in flow style using commas to separate the items and enclosing them in square brackets ([val1, val2, ...]).

menu: [pizza, pasta, hamburger, steak, salad]

Nested Sequences

Sequences can also be nested.

The following examples are all equivalent:

data:  [[1,  2],  [3,  4]]

data:
-
  - 1
  - 2
-
  - 3
  - 4

data:
- - 1
  - 2
- - 3
  - 4
Navigation