yq/pkg/yqlib/doc/operators/flatten.md
2021-12-21 15:02:07 +11:00

732 B

Flatten

This recursively flattens arrays.

Flatten

Recursively flattens all arrays

Given a sample.yml file of:

- 1
- - 2
- - - 3

then

yq eval 'flatten' sample.yml

will output

- 1
- 2
- 3

Flatten with depth of one

Given a sample.yml file of:

- 1
- - 2
- - - 3

then

yq eval 'flatten(1)' sample.yml

will output

- 1
- 2
- - 3

Flatten empty array

Given a sample.yml file of:

- []

then

yq eval 'flatten' sample.yml

will output

[]

Flatten array of objects

Given a sample.yml file of:

- foo: bar
- - foo: baz

then

yq eval 'flatten' sample.yml

will output

- foo: bar
- foo: baz