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
|
2022-01-28 01:45:43 +00:00
|
|
|
yq --null-input '[]'
|
2021-10-30 03:14:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
[]
|
|
|
|
```
|
|
|
|
|
|
|
|
## Collect single
|
|
|
|
Running
|
|
|
|
```bash
|
2022-01-28 01:45:43 +00:00
|
|
|
yq --null-input '["cat"]'
|
2021-10-30 03:14:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
- cat
|
|
|
|
```
|
|
|
|
|
|
|
|
## Collect many
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
a: cat
|
|
|
|
b: dog
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
2022-01-28 01:45:43 +00:00
|
|
|
yq '[.a, .b]' sample.yml
|
2021-10-30 03:14:39 +00:00
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
- cat
|
|
|
|
- dog
|
|
|
|
```
|
2021-11-03 04:00:28 +00:00
|
|
|
|