Identify map keys, whose value is a map that has direct child enabled: true
#802
-
Hello, I am new to yq v4. I am running Here is my document: Cruise Control:
speed: 100
enabled: true
Headlights:
broken: false
enabled: false
Gearbox:
tractionControl:
enabled: true
gear: 3
neutral: false
Climate Control:
temperature: 70
enabled: true
Make: "Toyota"
Passengers: [] I do not know all possible top level keys. I am looking for a general solution to identify the set of top level keys that have an
So far I have tried:
I've noticed that the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
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
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. |
Beta Was this translation helpful? Give feedback.
-
Thanks very much @mikefarah ! Here's my jq (edit: {
"Cruise Control": {
"speed": 100,
"enabled": true
},
"Headlights": {
"broken": false,
"enabled": false
},
"Gearbox": {
"tractionControl": {
"enabled": true
},
"gear": 3,
"neutral": false
},
"Climate Control": {
"temperature": 70,
"enabled": true
},
"Make": "Toyota",
"Passengers": []
}
|
Beta Was this translation helpful? Give feedback.
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: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.