How to map certain keys of an array to make another one in mule 4

I have an array -

[
    {
        "Number": "12345",
        "abc": {
            "group": "abc",
            "operation": "Create"
        },
        "def": {
            "group": "def",
            "operation": "Create"
        }
    },
    {
        "Number": "45678",
        "xyz": {
            "group": "xyz",
            "operation": "Update"
        },
        "sdf": {
            "group": "sfd",
            "operation": "Delete"
        }
    }
]

and need to convert into this form -

[
    {
        "Number": "12345",
        "group": "abc",
        "operation": "Create"
    },
    {
        "Number": "12345",
        "group": "def",
        "operation": "Create"
    },
    {
        "Number": "45678",
        "group": "xyz",
        "operation": "Update"
    },
    {
        "Number": "45678",
        "group": "sfd",
        "operation": "Delete"
    }
]

Trying to write dataweave expression for the same. The issue is that abc, def, xyz and all are objects which may or maynot come and can have different values.



Read more here: https://stackoverflow.com/questions/67000479/how-to-map-certain-keys-of-an-array-to-make-another-one-in-mule-4

Content Attribution

This content was originally published by shreyas kulkarni at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: