0

我必须在 dataweave 2.0 中将 null 替换为空白,我尝试了很多组合,但出现错误。

附上截图供您参考。

请提供任何相同的指针。

谢谢。在此处输入图像描述

4

2 回答 2

3

这是因为您将空白字符串分配给 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 ""
    )
}
于 2019-02-04T09:29:07.113 回答
0

最好使用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

于 2019-02-07T06:43:47.577 回答