y
y
yq
Search…
Flatten
This recursively flattens arrays.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>

Flatten

Recursively flattens all arrays
Given a sample.yml file of:
- 1
- - 2
- - - 3
then
yq 'flatten' sample.yml
will output
- 1
- 2
- 3

Flatten with depth of one

Given a sample.yml file of:
- 1
- - 2
- - - 3
then
yq 'flatten(1)' sample.yml
will output
- 1
- 2
- - 3

Flatten empty array

Given a sample.yml file of:
- []
then
yq 'flatten' sample.yml
will output
[]

Flatten array of objects

Given a sample.yml file of:
- foo: bar
- - foo: baz
then
yq 'flatten' sample.yml
will output
- foo: bar
- foo: baz
Copy link
On this page
Flatten
Flatten with depth of one
Flatten empty array
Flatten array of objects