Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link
SRash
  • 111
  • 1
  • 2
  • 7

filter array of objects using jq from json

im trying to fillter the below json data with jq and expected out-put as last.

cat data.json

{
    "params": {
        "filters": {},
        "group_by": [
            "service"
        ],
        "metrics": [
            "cocekop:count",
            "cocekop.seconds_to_first_ack:avg",
            "cocekop.seconds_to_resolve:avg",
            "cocekop.escalated:count"
        ],
        "since": "2022-03-01T15:00:00.000Z",
        "time_zone": "Asia/Tokyo",
        "until": "2022-03-02T14:59:59.000Z"
    },
    "report": {
        "groups": [
            [{
                    "id": "PKOLSA",
                    "name": "Commuincation"
                },
                {
                    "id": "PRKOLS",
                    "name": "Designation"
                },
                {
                    "id": "PKDFKDL",
                    "name": "Mapping"
                }
            ]
        ],
        "metrics": {
            "cocekop.escalated:count": [
                1,
                0,
                0
            ],
            "cocekop.seconds_to_first_ack:avg": [
                86,
                0,
                9
            ],
            "cocekop.seconds_to_resolve:avg": [
                8161,
                492,
                301
            ],
            "cocekop:count": [
                1,
                1,
                0
            ]
        }
    }
}

im expecting ouput as

id,name,cocekop:count
PKOLSA,Commuincation,1
PRKOLS,Designation,1
PKDFKDL,Mapping,0

Please help.