Skip to content

Identify map keys, whose value is a map that has direct child enabled: true #802

Answered by mikefarah
therealplato asked this question in Q&A
Discussion options

You must be logged in to vote

Although the example looks simple - it took me a while to get this one. Interested if there's something simpler and how it would be done in jq. Regardless:

yq e '. as $d | keys | .[] | select(. as $k | ( $d | .[$k] | select(tag=="!!map") | .enabled))' demo.yml

Basically we want to filter the keys of the yaml file, and to do that we need to use variables to control the context.

Each key we pass through a filter to see if it's a map in the original document and if it's enabled.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by therealplato
Comment options

You must be logged in to vote
2 replies
@mikefarah
Comment options

@mikefarah
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants