在这里,我需要在我的json arrayObject中查找value 1(颜色/大小),并Map到mule 4 dataweave中相同json数组对象的value 2(黄色/28英寸)。
请注意,systemAttributeName
不应与group
相同。只有当group == 'Color'
时,才应填充相应的systemAttributeName
JSON输入
{
"system": "Computer",
"description": "",
"details": "",
"systemDetails": [
{
"systemnumber": "A123",
"description": [
{
"group": "color",
"desc": "yellow"
},
{
"group": "variant",
"desc": "20k model"
},
{
"group": "category",
"desc": "Desktop"
}
]
},
{
"systemnumber": "B123",
"description": [
{
"group": "size",
"desc": "28 inch"
},
{
"group": "category",
"desc": "Laptop"
}
]
}
]
}
字符串
我的预期输出如下
{
"systemId": "A123",
"systemLevelDetails": [
{
"systemAttributeName": "Colordescription",
"values": "yellow"
},// if my corresponding input systemDetails.description has a group 'color' - then this should be present
{
"systemAttributeName": "Categorydescription",
"values": "Desktop"
}// if my corresponding input systemDetails.description has a group 'category' - then this should be present
]
}
{
"systemId": "B123",
"systemLevelDetails": [
{
"systemAttributeName": "Sizedescription",
"values": "28inch"
},// if my corresponding input systemDetails.description has a group 'size' - then this should be present
{
"systemAttributeName": "Categorydescription",
"values": "Laptop"
}
]
}
型
让我知道我如何才能做到这一点?
1条答案
按热度按时间zysjyyx41#
假设输出应该是数组(因为还能是什么呢?),它看起来和
payload.systemDetails
一样,只是键值改变了。一种方法是只对description
中的嵌套数组使用map和嵌套map。如果只允许description.group
中的某些值,我们可以使用filter()函数删除它们,通过验证group
值是否存在于有效值列表中。DataWeave脚本:字符串
输出量:
型
如果需要单独处理输出数组的每一项,只需在流中使用
<foreach>
作用域。