我必须在 dataweave 2.0 中将 null 替换为空白,我尝试了很多组合,但出现错误。
附上截图供您参考。
请提供任何相同的指针。
这是因为您将空白字符串分配给 dValue.doctorId 而不是 (doctorId)。在这里使用default
也更容易设置默认值。这是一个例子:
%dw 2.0
output application/xml
var doctorInformationList=[{doctorId: '1'},{doctorId: '2'}, {}]
---
root: {
DoctorInformationList: doctorInformationList map ((dValue, dIndex) ->
doctorId : dValue.doctorId default ""
)
}
最好使用when
- otherwise
。以下是针对您的问题的数据编织转换
%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
}
)
}
输出如下:
{
"DoctorInfoList": [
{
"docorId": "1",
"docorName": "A"
},
{
"docorId": "2",
"docorName": "B"
},
{
"docorId": "",
"docorName": "C"
},
{
"docorId": "",
"docorName": "D"
},
{
"docorId": "",
"docorName": null
}
]
}
替换doctorInfoList
为您的payload