y
y
yq
Search…
Flatten
This recursively flattens arrays.

Flatten

Recursively flattens all arrays
Given a sample.yml file of:
1
- 1
2
- - 2
3
- - - 3
Copied!
then
1
yq eval '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 eval '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 eval '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 eval 'flatten' sample.yml
Copied!
will output
1
- foo: bar
2
- foo: baz
Copied!
Last modified 29d ago