mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
36 lines
369 B
Markdown
36 lines
369 B
Markdown
|
# Keys
|
||
|
|
||
|
Use the `keys` operator to return map keys or array indices.
|
||
|
## Map keys
|
||
|
Given a sample.yml file of:
|
||
|
```yaml
|
||
|
dog: woof
|
||
|
cat: meow
|
||
|
```
|
||
|
then
|
||
|
```bash
|
||
|
yq eval 'keys' sample.yml
|
||
|
```
|
||
|
will output
|
||
|
```yaml
|
||
|
- dog
|
||
|
- cat
|
||
|
```
|
||
|
|
||
|
## Array keys
|
||
|
Given a sample.yml file of:
|
||
|
```yaml
|
||
|
- apple
|
||
|
- banana
|
||
|
```
|
||
|
then
|
||
|
```bash
|
||
|
yq eval 'keys' sample.yml
|
||
|
```
|
||
|
will output
|
||
|
```yaml
|
||
|
- 0
|
||
|
- 1
|
||
|
```
|
||
|
|