Reputation: 1225
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
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
Final Mapper expressions
$groupBy.id
mapped to id
jsonPath($, "$groups[*].type")
mapped to types
Resulting output
Upvotes: 0