I have a Java Object
as input payload:
{
"name"="Michael",
"surname"="Alpha",
"mail"="demo@gmail.com",
"gender"="Male"
}
I want change the gender value keeping the rest of the message:
%dw 2.0
output application/java
---
gender: if(payload.gender == "Male") "" else payload.gender
But it return only the gender field. How can I solve that?
The dataweave script needs to match your output structure and you are only outputting a single gender field.
One quick way yo just modify the current payload is using payload ++
.
If your payload is a map/object it will just replace the key if it exists or adds it if not. Example:
%dw 2.0
output application/java
---
payload ++ {gender: (if (payload.gender == "male") "" else payload.gender)}