Mule 在Dataweave 2.0中将Null替换为空白

Mule 在Dataweave 2.0中将Null替换为空白,mule,mule-studio,mule-el,mule-esb,mule-cluster,Mule,Mule Studio,Mule El,Mule Esb,Mule Cluster,在Dataweave2.0中,我必须用空格替换null,我尝试了许多组合,但都出现了错误 附上截图供您参考 请提供任何相同的指针 谢谢。 它是因为您将空白字符串分配给dValue.DOcTrID,而不是(DOCORID)。这里使用default设置默认值也更容易。以下是一个例子: %dw 2.0 output application/xml var doctorInformationList=[{doctorId: '1'},{doctorId: '2'}, {}] --- root: {

在Dataweave2.0中,我必须用空格替换null,我尝试了许多组合,但都出现了错误

附上截图供您参考

请提供任何相同的指针


谢谢。

它是因为您将空白字符串分配给dValue.DOcTrID,而不是(DOCORID)。这里使用
default
设置默认值也更容易。以下是一个例子:

%dw 2.0
output application/xml
var doctorInformationList=[{doctorId: '1'},{doctorId: '2'}, {}]
---
root: {
        DoctorInformationList: doctorInformationList map ((dValue, dIndex) -> 

        doctorId : dValue.doctorId default ""
    )
}

最好在-
时使用
,否则
。 下面是针对您的问题的dataweave转换

%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
    }
  ]
}
doctorinfo列表
替换为您的
有效负载