I am writing a shell script that will read from a text file line by line some item names stored in the $entry variable within a while loop. With a curl command, I retrieve a json which is given as sample json response. I need to be able to compare the input text value which is saved in $entry to all the values within the item_name array and return true/false depending on if the $entry value is present using jq library. I am able to retrieve the item names values using the jq command written below, but I am not familiar how to compare with the input string. when I use "select" command to compare, I get syntax error. I am quite new to jq and not proficient with using filters/select statement for comparison, any pointers on how to resolve it?
bash variable
$entry = "some value from a text file"
sample json response
"response": {
"numFound": 2,
"docs": [{
"country": "USA",
"item_name": [
"parachutes",
"air balloon"
]
},
{
"country": "Brazil",
"item_name": [
"gliders",
"aircraft carriers"
]
}
]
}
jq command
echo "$RESPONSE" | jq '.' | jq '.["response"]["docs"]' | jq '.[].item_name' | jq - r '.[]'
Update:
The jq command that works as expected is
echo $RESPONSE | jq -e '.' | jq -r '.["response"]["docs"] | .[].item_name ' | jq -s 'add' | jq 'any(. == "'"$entry"'") | if . == true then "Exact match" else "No Exact match" end'