I have JSON looking like that:
[
{
"file": "aaa.txt",
"destination": 1
},
{
"file": "bbb.txt",
"destination": 2
},
{
"file": "ccc.txt",
"destination": 3
},
{
"file": "ddd.txt",
"destination": 4
},
{
"file": "eee.txt",
"destination": 9
}
]
I'm trying to build a script in bash using command jq to get the number of items in JSON and use the vaules of file, destination in second command. To achieve the first one I use
count=$(curl 'http://mypage/json' | jq length)
I'm getting the number (count) of this elements (5 in this case). Next I want to build while loop from 5 to 1 to put file value into (nomen omen) file (script in the loop should create file called [destination] with [file] as content (example: for firstone file should by called 1 with aaa.txt as a content). And... this is my question - how can I put my JSON into array (or something)? I tried to use
arr=$(curl 'http://mypage/json' | jq'.[]')
but it puts whole json as one. Can you help me please?