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
- 1
2
- - 2
3
- - - 3
Copied!
then
1
yq 'flatten' sample.yml
Copied!
will output
1
- 1
2
- 2
3
- 3
Copied!

Flatten with depth of one

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

Flatten empty array

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

Flatten array of objects

Given a sample.yml file of:
1
- foo: bar
2
- - foo: baz
Copied!
then
1
yq 'flatten' sample.yml
Copied!
will output
1
- foo: bar
2
- foo: baz
Copied!