-1

I have the below data structure in JSON, which is a dictionary where each element is a list of dictionaries.

{
    "383e36d1-32e5-4705-8271-fa5e9e2ad538": [
        {
        "label": "blah",
        "group_label": "group_a",
        "id": "id_blah"
        },
        {
        "label": "bloh",
        "group_label": "group_b",
        "id": "id_bloh"
        }
    ],
    "38b8293c-00c4-4bcf-91eb-440da656c653": [
        {
        "label": "bim",
        "group_label": "group_c",
        "id": "id_bim"
        },
        {
        "label": "bam",
        "group_label": "group_d",
        "id": "id_bam"
        },
   ...
}

and I need a JMESPath query expression to turn it into:

{
    "383e36d1-32e5-4705-8271-fa5e9e2ad538": [
        {
        "label": "blah",
        "group_label": "group_a",
        },
        {
        "label": "bloh",
        "group_label": "group_b",
        }
    ],
    "38b8293c-00c4-4bcf-91eb-440da656c653": [
        {
        "label": "bim",
        "group_label": "group_c",
        },
        {
        "label": "bam",
        "group_label": "group_d",
        },
   ...
}

Basically keeping the same structure but removing the id key from every entry

  • 1
    The general approach on Stack Overflow is that you post your attempt, explain where you're stuck and what you don't understand about the behavior of the code you wrote. *"I have this input and I need this output, thank you"* is a work assignment, not a question. – Tomalak Nov 28 '19 at 17:12

1 Answers1

-1

In Node.js, you could use the following code:

var json = {
    "383e36d1-32e5-4705-8271-fa5e9e2ad538": [
        {
        "label": "blah",
        "group_label": "group_a",
        "id": "id_blah"
        },
        {
        "label": "bloh",
        "group_label": "group_b",
        "id": "id_bloh"
        }
    ],
    "38b8293c-00c4-4bcf-91eb-440da656c653": [
        {
        "label": "bim",
        "group_label": "group_c",
        "id": "id_bim"
        },
        {
        "label": "bam",
        "group_label": "group_d",
        "id": "id_bam"
        }
    ]
};

for (var key in json) {
    for (var index = 0; index < json[key].length; index++) {
        delete json[key][index].id;
    }
}
console.log(json);