Keys

Use the keys operator to return map keys or array indices.

Map keys

Given a sample.yml file of:

dog: woof
cat: meow

then

yq 'keys' sample.yml

will output

- dog
- cat

Array keys

Given a sample.yml file of:

- apple
- banana

then

yq 'keys' sample.yml

will output

Retrieve array key

Given a sample.yml file of:

then

will output

Retrieve map key

Given a sample.yml file of:

then

will output

No key

Given a sample.yml file of:

then

will output

Update map key

Given a sample.yml file of:

then

will output

Get comment from map key

Given a sample.yml file of:

then

will output

Check node is a key

Given a sample.yml file of:

then

will output

Last updated

Was this helpful?