yq/operators/map.md
2022-02-06 14:41:27 +11:00

539 B

Map

Maps values of an array. Use map_values to map values of an object.

{% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified.

yq e <exp> <file> {% endhint %}

Map array

Given a sample.yml file of:

- 1
- 2
- 3

then

yq 'map(. + 1)' sample.yml

will output

- 2
- 3
- 4

Map object values

Given a sample.yml file of:

a: 1
b: 2
c: 3

then

yq 'map_values(. + 1)' sample.yml

will output

a: 2
b: 3
c: 4