owsata
owsata

Reputation: 1225

Snaplogic - Expression Language Syntax - unique array value

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?

Upvotes: 0

Views: 780

Answers (1)

Bilesh Ganguly
Bilesh Ganguly

Reputation: 4131

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

Upvotes: 0

Related Questions