I am trying to split my json object into multiple json arrays.
{
"MusicCollection": [
{
"PutRequest": {
"Item": {
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Call Me Today"},
"AlbumTitle": {"S": "Somewhat Famous"}
}
}
},
{
"PutRequest": {
"Item": {
"Artist": {"S": "Acme Band"},
"SongTitle": {"S": "Happy Day"},
"AlbumTitle": {"S": "Songs About Life"}
}
}
},
{
"PutRequest": {
"Item": {
"Artist": {"S": "No One You Know"},
"SongTitle": {"S": "Scared of My Shadow"},
"AlbumTitle": {"S": "Blue Sky Blues"}
}
}
}
]
}
Command in below post works in linux for splitting the file into multiple putRequest arrays.
jq -cM --argjson sublen '2' 'range(0; length; $sublen) as $i | .[$i:$i+$sublen]' \
input.json | split -l 1 -da 3 - meta2_
Reference: Split a JSON array into multiple files using command line tools
Directly running below command in command prompt gives me 3 put requests.
jq ".MusicCollection[]" music.json
However, when I used below for loop in batch script, it just gives me }
.
for /f "tokens=*" %%a in ('music.json') do (
jq ".MusicCollection[]" music.json
set array_value=%%a
)
echo Array: %array_value%
Can someone please guide me as how I should get the same output of command prompt with the for loop?