Reputation: 11
I am trying to passing variables to JQ but the following code is not working as expected:
echo '{
"app": "K8s",
"version": "1.8",
"date": "2018-10-10"
}' | jq --arg app 'K8s' -c 'select(.app == [$app]).version'
However, following example works:
echo '{
"app": "K8s",
"version": "1.8",
"date": "2018-10-10"
}' | jq -r --arg app app 'select(.[$app] == "K8s").version'
why the first example is not working?
Thanks
Upvotes: 0
Views: 90
Reputation: 116870
In the first example, [$app]
is wrong: this expression produces an array. The jq program should be:
select(.app == $app).version
Upvotes: 1