YAML Arrays example

Arrays are a group of fixed-size elements. Array elements in the YAML file contain separate lines, Also called multiline array strings.

In YAML, array syntax is

let’s declare an array in any programming languages

["admin", "finance", "hr"]

Above written with yaml sequence also

- admin
- finance
- hr

Let’s declare the key and value as an array in YAML.

roles contain an array of admin, HR, and sales, finance

We have to use a sequence with key=roles, and the value is a multi-line array of strings.

Here is an example of the YAML sequence that is the same as multi-line strings.

- admin
- finance
- hr
- sales

Also, this can be represented in multiple ways


This is good as it is very easy to read and understand. or


Array of arrays in yaml in multiline strings

Suppose you have a list of employee objects in json that contain an array of arrays.

  "employees": [

YAML represents an array of arrays as follows

- - emp1
  - emp2
  - emp3
- - emp11
  - emp12
  - emp13