【问题标题】:json to xml using dataweave sum functionjson 到 xml 使用 dataweave sum 函数
【发布时间】:2017-05-07 20:18:04
【问题描述】:

我的输入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>

如果json中“AGE”字段的总和大于100,则我有一个条件,而不是xml中validity标签的值是'yes'否则'no'

你能帮我如何在 dataweave 中使用 sum 函数作为有效性字段吗?重点是我在 json 中获取“年龄”字段的数组。

干杯, 解算器

【问题讨论】:

    标签: mule dataweave


    【解决方案1】:

    这是您正在寻找的数据编织:

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

    【讨论】:

    • here .. %var agecombined 将不起作用,因为我正在获取年龄值一个我想在这里合并所有年龄的数组:-23+24+25 请告诉我如何对所有年龄求和这是数组而不是应用条件
    • Yevgeniy 的回答是正确的,试一试。 payload.StudentDetails.StudentType.Age 生成一个数组。你可以把它写成payload.StudentDetails.*StudentType.Age这样更清楚,但结果是一样的。
    • 不,它不起作用,它给出了一个错误“null to array”,我已经用准确的字段更新了我的 json,你现在可以帮帮我吗……抱歉再更新一个 :-(.. ..我必须对年龄的 23+24+25 求和并进行验证。
    【解决方案2】:

    试试这个数据编织脚本

    %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 将获得年龄数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多