MuleSoft转换在使用DWL进行JSON有效负载转换时出错

时间:2018-04-02 10:35:27

标签: mule

我是MuleSoft的新手。我正在尝试使用transform来转换JSON有效负载。 我想将我的有效负载转换为

输入:

{
    "ResponseStatus": {
        "Status": "SUCCESS",
        "StatusText": "SUCCESS"
    },
    "Processes": {
        "Process": [
            {
                "ProcessId": "1234567",
                "ProcessProperties": {
                    "Property": [
                        {
                            "Name": "XXXXXXXXXXX",
                            "Value": "11111111",
                            "Desc": "YYYYYYYY"
                        },
                        {
                            "Name": "AAAAAAAAA",
                            "Value": "2222222",
                            "Desc": "BBBBBBBB"
                        },
                        {
                            "Name": "QQQQQQQQQ",
                            "Value": "#######",
                            "Desc": "CCCCCCCC"
                        },
                        {
                            "Name": "NNNNNNN",
                            "Value": "IIIIIIII",
                            "Desc": "UYUYUYUY"
                        }
                    ]
                },
                "EditMode": "CCCCCC",
                "ProcessType": "ABCD",
                "AppName": "VFVFVGBG",
                "StatusHistory": {
                    "STS": [
                        {
                            "Sts": "COMPLETED"
                        }
                    ]
                }
            }
        ]
    }
}

输出:

[
  {
    "ProcessId": "1234567",
    "AAAAAAAAA": "2222222",
    "QQQQQQQQQ": "#######"
  }
]

我已阅读Mulesoft link下方的DWL参考资料。另请参阅this SO链接。

以下是我到目前为止所尝试的内容,

%dw 1.0
%output application/json
---
{
"ProcessId": (payload.Processes.Process.ProcessId)[0],

AAAAAAAAA: {
                        (payload.Processes.Process.ProcessProperties.Property mapObject {
($.Name):$.Value when $.Name =="AAAAAAAAA" otherwise ""
                        })
            },
   QQQQQQQQQ: {

        (payload.Processes.Process.ProcessProperties.Property mapObject {
($.Name):$.Value when $.Name =="QQQQQQQQQ" otherwise ""
                         })
            }
}

我仍然无法获得所需的输出。

它给了我“不能强迫a:数组到a:key”

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

输入json中的“property”json元素是“Array”,它无法解析为单个值。

请尝试下面的代码片段并告诉我,如果这样可以提供您的de / o。

payload.Processes.Process map (
(val , index) ->

    {"ProcessId":(payload.Processes.Process.ProcessId)[0]
     ,

    (val.ProcessProperties.Property map {

        (($.Name) : $.Value) when  $.Name =='AAAAAAAAA'  }

    ),

    (val.ProcessProperties.Property map {

        (($.Name) : $.Value) when  $.Name =='QQQQQQQQQ'  }

    )

}
)