cancel
Showing results for 
Search instead for 
Did you mean: 

Key value pair from object array

deepak_shaw
Contributor

Hi,
I would like to create the below outbound message from an incoming object array.

{
    "root": {
        "elementName": {
            "@attributeName": "attributeValue",
            "$": "elementValue"
        },
        "repeatedElement": [
            {
                "key": {
                    "@attr": "attr1",
                    "$": "key1"
                },
                "value": "value1"
            },
            {
                "key": {
                    "@attr": "attr2",
                    "$": "key2"
                },
                "value": "value2"
            }
        ]
    }
}

Any suggestion please on the repeated elements, attributes, and values?
Thanks,
Deepak Shaw

1 ACCEPTED SOLUTION

Done, check the pipeline and let me know if this works for you. Can be made with multiple mappers or a JSON Schema as well, but this is simpler in terms of snaps usage.

Key value pair from object array_2022_05_20.slp (4.3 KB)

View solution in original post

11 REPLIES 11

$InvoiceLines.map(x=>{"LineNumber":{"@LineExtAmtExclTax":x.LineExtAmtExclTax,"$":x.LineNumber},"value":x.Employee})

I’m glad I could help.

With the expression above, we’re mapping a specific value to every object inside the $InvoiceLines array. Basically the .map() function will iterate through the array, and for every object, it will map a JSON structure, using the values of that object.