I want to iterate over the below array received from a curl response and print the values of all the "path" properties on a new line but I am getting unwanted results everytime (may be i dont know how to do)
{
"values": [
{
"old": {
"path": "textfile.txt"
},
"size":1
},
{
"old": {
"path": "text1file.txt"
},
"size":1
}
]
}
Below is my bash script which returns only the first value, also when i try to get the length it always returns 1 instead of 2
FILES=$(curl "https://url" | jq '(.values[].old.path)')
echo "$FILES"
echo "length is: ${#FILES[@]}"
for i in "${FILES[@]}"; do
echo "num1 ${i}"
done
The response received for line 2 is below:
"textfile.txt"
"text1file.txt"
The response received for line 3:
length is: 1
The expected response of line 5 is:
num1 "textfile.txt"
num1 "text1file.txt"
But instead it gives:
num1 "textfile.txt"
"text1file.txt"
PS: I am doing the above script in bitbucket pipelines to implement CD process.
Does any one know what's wrong in the above for
loop?
EDIT: I also tried the below script it still gives only the first value.
curl -H 'Content-Type:application/json' https://url >> myfilenames.json
for i in $(jq -r '.values[].old.path' myfilenames.json); do
echo "${i}"
done