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

28 lines
387 B
Markdown
Raw Normal View History

2021-11-03 04:00:58 +00:00
# Keys
Use the `keys` operator to return map keys or array indices.
2022-09-30 00:27:35 +00:00
## Check node is a key
Given a sample.yml file of:
```yaml
2023-05-02 04:07:59 +00:00
a: frog
2022-09-30 00:27:35 +00:00
```
then
```bash
yq '[... | { "p": path | join("."), "isKey": is_key, "tag": tag }]' sample.yml
```
will output
```yaml
- p: ""
isKey: false
tag: '!!map'
- p: a
isKey: true
2023-05-02 04:07:59 +00:00
tag: null
'!!str': null
2022-09-30 00:27:35 +00:00
- p: a
isKey: false
tag: '!!str'
```