Hello I’ve the following json and try to get all parents who have the "linux-image-amd64"
{
"web-prode-01.example.de": "ERROR: Problem encountered installing package(s). Additional info follows:nnchanges:n ----------n linux-image-amd64:n ----------n new:n old:n 6.1.55-1nerrors:n - Running scope as unit: run-rad31bddd35ec452b9d67fef004ce3daf.scopen E: Sub-process /usr/bin/dpkg returned an error code (1)",
"web-prode-04.example.de": {
"linux-image-amd64": {
"old": "5.10.197-1",
"new": "5.10.205-2"
},
"linux-image-5.10.0-27-amd64": {
"old": "",
"new": "5.10.205-2"
}
},
"lmrelaunch.example.de": {
"linux-image-6.1.0-0.deb11.13-amd64": {
"old": "",
"new": "6.1.55-1~bpo11+1"
},
"linux-image-amd64": {
"old": "6.1.38-4~bpo11+1",
"new": "6.1.55-1~bpo11+1"
}
}
}
I tried jq -r 'keys[] as $k | "($k) (.[$k]."linux-image-amd64")"'
but I just got one entry instead of two
2
Answers
working demo here
Returns :
You should check if the context
has
that key. Also, to prevent the string from failing when trying to applyhas
on it, either filter forobjects
, or suppress the error with?
. In either case, use this condition to filter the results usingselect
.You can then construct your output using
$k
, e.g.: