I have to replace null with blanks in dataweave 2.0 , I tried many combinations but getting error in it .
The screenshot is attached for your reference .
Please provide any pointers for the same .
I have to replace null with blanks in dataweave 2.0 , I tried many combinations but getting error in it .
The screenshot is attached for your reference .
Please provide any pointers for the same .
Gurpreet Singh
On
It's better to use when - otherwise.
Below is dataweave transform for your problem
%dw 2.0
%output application/json
%var doctorInfoList=[{doctorId: '1', doctorName : 'A'},{doctorId: '2', doctorName : 'B'},
{doctorId: null, doctorName : 'C'},{doctorId: '', doctorName : 'D'},{}]
---
{
DoctorInfoList: doctorInfoList map ((doctorValue, doctorIndex) -> {
"docorId" : '' when doctorValue.doctorId is :null otherwise doctorValue.doctorId,
"docorName" : doctorValue.doctorName
}
)
}
Output would be like :
{
"DoctorInfoList": [
{
"docorId": "1",
"docorName": "A"
},
{
"docorId": "2",
"docorName": "B"
},
{
"docorId": "",
"docorName": "C"
},
{
"docorId": "",
"docorName": "D"
},
{
"docorId": "",
"docorName": null
}
]
}
Replace doctorInfoList with your payload

Its because you are assigning the blank string to dValue.doctorId and not (doctorId). Also using
defaultis easier here for setting default values. Here is an example: