You are not logged in.
I have the following contacts.json file:
[
{
"name": "John",
"email": "john@email.com"
},
{
"name": "George",
"email": "george@email.com"
},
{
"name": "Sally",
"email": "sally@email.com"
}
]
If I run this jq command, I get the expected output:
[tony@linux ~]$ jq '.[] | select(.name == "John")' contacts.json
{
"name": "John",
"email": "john@email.com"
}
But if I use a bash string for the needle in the haystack, jq doesn't find it (there's no output). Does anyone know why?
[tony@linux ~]$ name="John" ; jq -r '.[] | select(.name == "$name")' contacts.json
[tony@linux ~]$
Last edited by tony5429 (2018-08-24 12:56:40)
Offline
jq --arg name "$name" '.[] | select(.name == $name)' contacts.json
Offline
Ah; that works! Thanks!
Offline