yq/pkg/yqlib/doc/Collect into Array.md

42 lines
441 B
Markdown
Raw Normal View History

2020-11-17 22:44:16 +00:00
# Collect into Array
This creates an array using the expression between the square brackets.
2020-11-22 02:16:54 +00:00
## Collect empty
2020-11-17 22:44:16 +00:00
Running
```bash
yq eval --null-input '[]'
```
will output
```yaml
2020-11-22 02:50:32 +00:00
[]
2020-11-17 22:44:16 +00:00
```
2020-11-22 02:16:54 +00:00
## Collect single
2020-11-17 22:44:16 +00:00
Running
```bash
yq eval --null-input '["cat"]'
```
will output
```yaml
- cat
```
2020-11-22 02:16:54 +00:00
## Collect many
2020-11-17 22:44:16 +00:00
Given a sample.yml file of:
```yaml
a: cat
b: dog
```
then
```bash
yq eval '[.a, .b]' sample.yml
```
will output
```yaml
- cat
- dog
```