How do I transform this nested object to a flattened object using jq?

Viewed 993

I need to transform this input into an unnested object using jq. In Python, I could transform it properly as follows.

output = {(k1 + '-' + k2): v2 for k1, v1 in input.iteritems() for k2, v2 in v1.iteritems()}

But I could not figure out how to do this in jq. The documentation for operating on nested objects is quite poor.

{
    "group1-permission": {
        "address": "test1",
        "others": "test2",
        "packet-capture": "test3",
        "policy": "test4",
        "schedule": "test5",
        "service": "test6"
    },
    "group2-permission": {
        "config": "none",
        "data-access": "none",
        "report-access": "none",
        "threat-weight": "none"
    },
    "group3-permission": {
        "antivirus": "none",
        "application-control": "none",
        "casi": "none",
        "data-loss-prevention": "none",
        "dnsfilter": "none",
        "icap": "none",
        "ips": "none",
        "spamfilter": "none",
        "voip": "none",
        "waf": "none",
        "webfilter": "none"
    }
}

The output should look like this:

{
    "group1-permission-address": "test1",
    "group1-permission-others": "test2",
    "group1-permission-packet-capture": "test3",
    "group1-permission-policy": "test4",
    "group1-permission-schedule": "test5",
    "group1-permission-service": "test6",
    "group2-permission-config": "none",
    "group2-permission-data-access": "none",
    "group2-permission-report-access": "none",
    "group2-permission-threat-weight": "none",
    "group3-permission-antivirus": "none",
    "group3-permission-application-control": "none",
    "group3-permission-casi": "none",
    "group3-permission-data-loss-prevention": "none",
    "group3-permission-dnsfilter": "none",
    "group3-permission-icap": "none",
    "group3-permission-ips": "none",
    "group3-permission-spamfilter": "none",
    "group3-permission-voip": "none",
    "group3-permission-waf": "none",
    "group3-permission-webfilter": "none"
}
1 Answers
Related