Reputation: 4242
I am new for mule and i am trying to fetch below hashmap memberId value in dataweave but below code getting compile time error, Can some one help me to how do we fetch memebrId value alone from below hasmap?.
{
"0":{
"key":"auth",
"value":true
},
"1":{
"key":"memebrId",
"value":"ESC0099123"
},
"2":{
"key":"name",
"value":"Ramakrishna"
}
}
(payload pluck $ filter ($.key == "memebrId"))[0].value
Upvotes: 0
Views: 2054
Reputation: 4303
you could do something like this
%dw 2.0
output application/json
---
(payload pluck $ filter ($.key == "memebrId"))[0].value
Upvotes: 3
Reputation: 3262
You can take all values of the object as an array using valuesOf
, and then filter the array to get the object containing memberId
which will give you an array of single object related to memberId.
%dw 2.0
output application/json
---
valuesOf(payload)[?($.key == 'memebrId')][0].value
The [?($.key == 'memebrId')]
part is an alternative selector to filter
you can use to shorten the overall expression, and avoid some extra braces. Since you are new to this, I will give the expanded version
(valuesOf(payload) filter ((item) -> item.key == 'memebrId'))[0].value
Upvotes: 3