I have a JSON-file like the one below:
{
"Results": [
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "1.21.1ubuntu2.1"
},
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2"
},
{
"Severity": "HIGH",
"VulnerabilityID": "CVE-2016-2781"
}
]
}
I would like to create the following JSON-file:
[
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "1.21.1ubuntu2.1",
"VulnerabilityID": ""
},
{
"Severity": "LOW",
"InstalledVersion": "1.21.1ubuntu2",
"FixedVersion": "",
"VulnerabilityID": ""
},
{
"Severity": "HIGH",
"InstalledVersion": "",
"FixedVersion": "",
"VulnerabilityID": "CVE-2016-2781"
}
]
I have tried iterating over the first JSON-file, but when I do so in the following way, I get random parsing errors (with the real JSON-file I am working with). So I think there is something off about the piping that I am doing.
jq -c '.Results[]' my.json | while read i; do
echo $i;
done
In the JSON-file I am working with jq -c '.Results[]' works perfectly, but when I do jq operations on the resulting $i while iterating, I suddently get several parsing errors.
Is there better way to iterate over key-value-pairs in a JSON-file? Ofcause I could just install Python/R and do the typical drill, but I would really like for this to work in a shell script.