Quantcast
Viewing all articles
Browse latest Browse all 519

jq filter objects based on value of a property (not key)

I have a structure like this:

[  { "name":"Genus", "value": "canis" }  { "name":"env.VAR1", "value": "dogsdrool"  { "name":"env.VAR2", "value": "catsrule" }]

I want to select the objects where the value of the name property starts with "env." (equivalently, where it matches the regex "^env\.")and then concatenate the name property value with the value property value like this:

env.VAR1="dogsdrool"env.VAR2="catsrule"

For the first part I've flailed around with select and gotten basically nowhere. It seems like this should not be hard, but it eludes me. This is not filtering based on key but on a property value.

For the second part I've got this, which works well. I just can't figure out how to filter only the objects where the name property starts with env.

|"\(.name) = \(.value)"

Viewing all articles
Browse latest Browse all 519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>