Short answer (TL; DR)
- In fact, yes, this is only possible with native jmespath
- The problem is that queries to the original dataset will be extremely cumbersome because the original dataset is poorly normalized for this kind of general jmespath query.
example
The following (too long) jmespath query for source data in OP ...
[ { "item_key": 'a' ,"feature_enabled": @.a.feature.enabled ,source_object: @.a } ,{ "item_key": 'b' ,"feature_enabled": @.b.feature.enabled ,source_object: @.b } ,{ "item_key": 'c' ,"feature_enabled": @.c.feature.enabled ,source_object: @.c } ]|[? feature_enabled == 'true']
... gives the following result
[ { "item_key": "a", "feature_enabled": true, "source_object": { "feature": { "enabled": true } } } ]
This is identical or substantially similar to the desired result, but the fact that we had to bend our brains to get to it suggests that we are trying to push a square peg through a round hole.
Traps
The reason this jmespath query looks so long and cumbersome is because the original dataset itself is poorly normalized for the general jmespath query.
This is because it uses object keys as a top-level matching method when a sequential indexed list would suffice.
When you have a data set that can contain an arbitrary number of values, it is almost always preferable to use a sequence to match the top level instead of the keys of the object.
If you find that you can do something in jmespath, but you need to modify the jmespath request whenever you add another “record” to the “record set of arbitrary (not fixed) length”, you are fighting with Jmespath, not working with him
Whenever you see a query that seems “impossible to execute” with Jmespath, you are almost certainly dealing with a data structure using objects where sequences may be more appropriate.
Object keys usually mean a fixed number of properties that jmespath can handle just fine.
Even the properties of an object of arbitrarily deep nesting are simply good if these properties of the object are not used as a substitute for sequential enumeration.
Things start to become uncomfortable when you discover that you need to create sequences of objects to go around object objects ... which is quite doable in jmespath, but it will be painful.
see also