我的输入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中的"年龄"字段大于XML中有效性标签的值100,则是'是'else'else''n'n'n'
您可以帮助我如何在dataWeave中使用sum函数作为有效性字段,重要的一点是我在JSON中获得了"年龄"字段的数组。
欢呼,Bsolver
这是您要查找的数据拖曳:
%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"
}
尝试此DataWeave脚本
%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
将获得年龄的数组。