I have the following JSON data:
{
"Jobs":[
{"JobId": 111, "ArchiveId": 333},
{"JobId": 112, "ArchiveId": 333},
{"JobId": 113, "ArchiveId": 2323},
{"JobId": 114, "ArchiveId": 444}
]
}
And here's the shell script that looks at the JSON object:
count_again=0
jq -r '.Jobs |= unique_by(.ArchiveId)' my-json-archiving.json \
| while IFS= read -r job; do
count_again=$(($count_again + 1))
echo $job
echo $count_again
done
My first step worked by filtering any duplicates by a certain key (.ArchiveId). Once that's done I want to loop through the result. Below is what I have, the main issue with that is it actually reads through line by line. I think it's got to do with the $job
that I return.
I'm very new to shell scripting so I'm not certain on how to return the object that it's looping through when reading the object