'Change value Array of Objects in mulesoft
I am beginner for mulesoft I have output payload transform message as below but I have to replace inside promotions array planChangeRequired attribute value as true always, can some one help me how can we replace it.
output Payload
{
"content": {
"data": {
"sharedDataGroups": [
{
"empId": 100,
"empName": "Ram"
},
{
"empId": 200,
"empName": "Santhosh"
}
],
"promotions": [
{
"id": "14400007",
"discount": 10.0,
"planChangeRequired": false
}
]
}
},
"meta-info": {
"version": "V1",
"timestamp": "2022-02-11T12:48:27.679"
}
}
Expected Result
{
"info": {
"sharedDataGroups": [
{
"empId": 100,
"empName": "Ram"
},
{
"empId": 200,
"empName": "Santhosh"
}
],
"promotions": [
{
"id": "14400007",
"discount": 10.0,
"planChangeRequired": **true**
}
]
},
"meta-info": {
"version": "V1",
"timestamp": "2022-02-11T12:48:27.679"
}
}
Solution 1:[1]
try the below code
%dw 2.0
output application/json
---
payload update {
case .info -> $ update {
case promo at .promotions -> promo map ((item, index) -> item update {
case .planChangeRequired -> "true"
}
)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harsha Shivamurthy |
