Transform Webhook array for use in HTTP request

I’m trying to pass an array contained in a Webhook call to a HTTP request module, but I need to change the array/collection/key names before doing so.

This is the relevant array contained in the webhook call:

"packages": [
    {
        "name": "Package 1",
        "weight_in_oz": 4,
        "width": 12,
        "length": 15,
        "height": 4,      
    },
    {
        "name": "Package 2",
        "weight_in_oz": 1.08,
        "width": 8,
        "length": 12,
        "height": 2,
    }
]

I need the array to look like this:

"shipments": [
        {
            "parcel": {
                  "weight": "10.2",
                  "length": "6",
                  "width": "6",
                  "height": "4"
            }
        },
        {
            "parcel": {
                  "weight": "10.2",
                  "length": "6",
                  "width": "6",
                  "height": "4"
            }
        }
    ]

Following this post, when I use Parse JSON and Aggregate to JSON I only get a single collection instead of 2.

I think you could parse JSON, iterate the packages array, aggregate the data back into an array, and finally, create a JSON of the desired structure. It could probably be done a little more efficiently, but I’ll attach a blueprint of what I’ve come up with.


shipments.json (7.3 KB)

1 Like