Snaplogic - Expression Language Syntax - unique array value

695 Views Asked by At

I am using following EL

jsonPath($, "$array.map({id: value.get('id'), type: value.get('type') })")

which produces the next variable ...

But the key(id) is not kept unique ?!

        [{
            "id": "1",
            "type": "1"
        },
        {
            "id": "1",
            "type": "2"
        },
        {
            "id": "2",
            "type": "1"
        }]

What can i use in snaplogic expression language or a snap to get the following unique key array :

           [{
                "id": "1",
                "types": ["1", "2"],
            {
                "id": "2",
                "type": ["1"]
            }]

Any ideas?

1

There are 1 best solutions below

0
On

Use Group By Fields snap to group based on id and then use a simple mapper to create the desired JSON. Please note that you have to sort the incoming documents by id before doing the group by.

Sample Pipeline

enter image description here

Final Mapper expressions

$groupBy.id mapped to id

jsonPath($, "$groups[*].type") mapped to types

Resulting output

enter image description here