yq/operators/collect-into-array.md

42 lines
441 B
Markdown
Raw Normal View History

2021-10-30 03:14:39 +00:00
# Collect into Array
This creates an array using the expression between the square brackets.
2021-11-03 04:00:28 +00:00
## Collect empty
2021-10-30 03:14:39 +00:00
Running
```bash
yq eval --null-input '[]'
```
will output
```yaml
[]
```
## Collect single
Running
```bash
yq eval --null-input '["cat"]'
```
will output
```yaml
- cat
```
## Collect many
Given a sample.yml file of:
```yaml
a: cat
b: dog
```
then
```bash
yq eval '[.a, .b]' sample.yml
```
will output
```yaml
- cat
- dog
```
2021-11-03 04:00:28 +00:00