DataWeave-如何在数组中的一个对象中以相同的顺序加入SKU列表
如何在数组中的一个对象中以相同的顺序加入SKU列表。
输入:
[{
"number": "7358",
"sku": "301-01",
"desc": "1"
}, {
"number": "7358",
"sku": "301-02",
"desc": "2"
}, {
"number": "7359",
"sku": "301-03",
"desc": "3"
}, {
"number": "7359",
"sku": "301-03",
"desc": "4"
}, {
"number": "7360",
"sku": "301-03",
"desc": "5"
}]
输出:
[{
"number": "7358",
"list": [{
"sku": "301-01",
"desc": "1"
}, {
"sku": "301-02",
"desc": "2"
}]
}, {
"number": "7359",
"list": [{
"sku": "301-03",
"desc": "3"
}, {
"sku": "301-03",
"desc": "4"
}]
}, {
"number": "7360",
"list": [{
"sku": "301-03",
"desc": "5"
}]
}]
输出我们只创建一个新的“列表”数组,其中包含具有共同顺序的SKU和DESC。任何帮助将不胜感激。谢谢。
How to join the list of sku with same order in one object in the array.
Input:
[{
"number": "7358",
"sku": "301-01",
"desc": "1"
}, {
"number": "7358",
"sku": "301-02",
"desc": "2"
}, {
"number": "7359",
"sku": "301-03",
"desc": "3"
}, {
"number": "7359",
"sku": "301-03",
"desc": "4"
}, {
"number": "7360",
"sku": "301-03",
"desc": "5"
}]
Output:
[{
"number": "7358",
"list": [{
"sku": "301-01",
"desc": "1"
}, {
"sku": "301-02",
"desc": "2"
}]
}, {
"number": "7359",
"list": [{
"sku": "301-03",
"desc": "3"
}, {
"sku": "301-03",
"desc": "4"
}]
}, {
"number": "7360",
"list": [{
"sku": "301-03",
"desc": "5"
}]
}]
Output we just create a new "list" array that contains the skus and the desc that have the order in common. Any help would be appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗨,萨利姆(Salim)所示的最好方法是我进行了一些修改,
简单的组件是组的关键是组的标准,因此它是数字,最简单的重新构建输出结构的方法是通过执行地图和删除。 “数字”字段
Hi The best way as shown by Salim is the groupBy I did a few modifications
Simple the key of the groupBy is the criteria that was group so it is the number and the simplest way to re build the output structure is by doing the map and removing the "number" field
尝试此脚本:
这是与输出匹配的更新脚本:
Try this script:
Here is the updated script that matches the output:
正如其他经验丰富的成员所提到的那样,
groupby
是实现这一目标的正确方法。但是,我注意到给定方法的输出有差异。以下脚本将输出一系列项目。输出
输入
As other experienced members have mentioned,
groupBy
is the right way to achieve this. However, I noticed there is a difference in the output with the given approaches. The following script will output an array of items.Output
Input