I have below json file
{
"total": 64,
"p": 1,
"ps": 1,
"paging": {
"pageIndex": 1,
"pageSize": 1,
"total": 64
},
"effortTotal": 216,
"issues": [
{
"key": "AX8lZNY1h5xTw2fmJuX6",
"rule": "xml:S125",
"severity": "MAJOR",
"component": "X8lXT9yjCYHsI0QujFF:pom.xml",
"project": "X8lXT9yjCYHsI0QujFF",
"line": 29,
"hash": "6e7405674b46c05cd7d7fc9433dbb323",
"textRange": {
"startLine": 29,
"endLine": 33,
"startOffset": 6,
"endOffset": 22
},
"flows": [],
"status": "OPEN",
"message": "Remove this commented out code.",
"effort": "5min",
"debt": "5min",
"author": "[email protected]",
"tags": [
"unused"
],
"creationDate": "2021-12-19T18:54:28+0100",
"updateDate": "2022-02-23T08:03:15+0100",
"type": "CODE_SMELL",
"scope": "MAIN"
}
],
"components": [
{
"key": "X8lXT9yjCYHsI0QujFF:pom.xml",
"enabled": true,
"qualifier": "FIL",
"name": "pom.xml",
"longName": "pom.xml",
"path": "pom.xml"
},
{
"key": "X8lXT9yjCYHsI0QujFF",
"enabled": true,
"qualifier": "TRK",
"name": "my-app",
"longName": "my-app"
}
],
"facets": [
{
"property": "types",
"values": [
{
"val": "BUG",
"count": 34
},
{
"val": "CODE_SMELL",
"count": 30
},
{
"val": "VULNERABILITY",
"count": 0
}
]
}
]
}
And I want to print values like below
BUG=34
I tried below as work around but its not printing as per my requirement
jq -r '.facets[].values[0].val,.facets[].values[0].count' file.json
which prints like below
BUG
34
but again I have to mention [0] for BUG [1] for CODE_SMELL so on
is there is any way I can do this so that it should print like below
BUG=34
CODE_SMELL:30
VULNERABILITY:0 (it will be null but I can put condition to print it is as zero in shell script while referring it as variable)
Please guide I am newbie to JQ, i know how to do it with sed but it needs more steps to add in script.