Reputation: 1864
I have a JSON content as embedded in this link jq-play. The JSON content is large and couldn't be accommodated here.
Currently, I manage to get the values by
[.[keys[] | select(contains("VMIMAGE"))]]
but the key names, i.e. CP-COMPUTEENGINE-VMIMAGE-F1-MICRO
aren't present in the result. How do I get it?
Upvotes: 15
Views: 18232
Reputation: 116919
It looks like you want to take a "slice" of the object by selecting just those keys containing a certain string. Using your query as a model, this can most easily be accomplished using a query of the form with_entries( select(...) )
, e.g.:
.gcp_price_list
| with_entries( select(.key|contains("VMIMAGE")))
Upvotes: 29