使用dataweave sum函数的json到xml

时间:2017-05-07 20:18:04

标签: mule dataweave

我的输入json如下: -

{
  "Studentvalue": [
    {
      "StudentDetails": {
        "valueId": "default",
        "reason": "default",
        "type": "high",
        "Schoolbudget": [
          {
            "Id": "100",
            "Age": "23"
          },
          {
            "Id": "101",
            "Age": "24"
          },
          {
            "Id": "102",
            "Age": "25"
          }
        ],
        "isApplicable": "boolean",
        "isNotified": "boolean"
      }
    }
  ]
}

输出xml是:

<schoolmemo>
<active>yes<active>
<schooltype>Primary<schooltype>
<validity>?<validity>
</schoolmemo>

如果&#34; AGE&#34;的总和,我有一个条件json中的字段大于100,而xml中的有效性标记的值是&#39;是&#39;别的&#39;不&#39;

你能帮助我如何在数据编织中使用sum函数来获得有效性字段,重要的是我得到了&#34; age&#34;在json的领域。

干杯, Bsolver

1 个答案:

答案 0 :(得分:0)

试试这个数据编辑脚本

%dw 1.0
%output application/xml
%var sumOfAge = sum payload.Studentvalue.StudentDetails.Schoolbudget..Age
---
schoolmemo: {
    active: "yes",
    schooltype: "Primary",
    validity: "yes" when sumOfAge < 100 otherwise "no"
}

payload.Studentvalue.StudentDetails.Schoolbudget..Age将获得一系列年龄。