yq/pkg/yqlib/doc/operators/map.md

41 lines
391 B
Markdown
Raw Normal View History

2021-11-30 23:32:36 +00:00
# Map
Maps values of an array. Use `map_values` to map values of an object.
## Map array
Given a sample.yml file of:
```yaml
2023-05-30 05:05:28 +00:00
- 1
- 2
- 3
2021-11-30 23:32:36 +00:00
```
then
```bash
2022-01-27 06:21:10 +00:00
yq 'map(. + 1)' sample.yml
2021-11-30 23:32:36 +00:00
```
will output
```yaml
2023-05-30 05:05:28 +00:00
- 2
- 3
- 4
2021-11-30 23:32:36 +00:00
```
## Map object values
Given a sample.yml file of:
```yaml
2023-05-30 05:05:28 +00:00
a: 1
b: 2
c: 3
2021-11-30 23:32:36 +00:00
```
then
```bash
2022-01-27 06:21:10 +00:00
yq 'map_values(. + 1)' sample.yml
2021-11-30 23:32:36 +00:00
```
will output
```yaml
2023-05-30 05:05:28 +00:00
a: 2
b: 3
c: 4
2021-11-30 23:32:36 +00:00
```