I'm trying to process the result of a cURL request, piped into jq
, which returns an array of JSON objects like so:
[
{
"first_name" : "John",
"last_name" : "Doe"
},
{
"first_name" : "bat",
"last_name" : "man"
}
]
Which I then try to format into a JSON array and read through by running
item_list=`curl "https://linkhere.com" | jq`
for item in ${item_list[@]}; do
echo "item is $item"
done
However, the items in the array are being read like strings, not JSON objects, outputting:
item is [
item is {
item is "John":
item is "Doe"
item is },
...
I want to iterate through each object in the JSON array to extract and store the first_name
and last_name
values. How can I go about properly doing this ?