mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
28 lines
387 B
Markdown
28 lines
387 B
Markdown
# Keys
|
|
|
|
Use the `keys` operator to return map keys or array indices.
|
|
|
|
## Check node is a key
|
|
Given a sample.yml file of:
|
|
```yaml
|
|
a: frog
|
|
```
|
|
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
|
|
tag: null
|
|
'!!str': null
|
|
- p: a
|
|
isKey: false
|
|
tag: '!!str'
|
|
```
|
|
|