我有以下的投入
输入1
[{
"id": "3857"
}, {
"id": "57"
}]输入2
[{
"Date": "2022-11-30",
"name": "salesorder",
"brand": "Apple",
"Requests": "111",
"price": "917.65"
}, {
"Date": "2022-11-13",
"name": "orders",
"brand": "TV",
"Requests": "11",
"price": "91.60"
}]输入3
[{
"count": "3"
}, {
"count": "4"
}]输入4
[{
"stock": "21",
"sold": "112"
}, {
"stock": "2",
"sold": "12"
}]期望输出
[{
"id": "3857",
"Date": "2022-11-30",
"name": "salesorder",
"brand": "Apple",
"Requests": "111",
"price": "917.65",
"count": "3",
"stock": "21",
"sold": "112"
},
{
"id": "57",
"Date": "2022-11-13",
"name": "orders",
"brand": "TV",
"Requests": "11",
"price": "91.60",
"count": "4",
"stock": "2",
"sold": "12"
}
]发布于 2022-12-02 21:32:02
假设所有数组的大小相同,则可以使用映射的每个元素的索引号(默认情况下为$$)从每个项映射键值的每个元素的每个元素。
%dw 2.0
output application/json
var input1=[{"id": "3857"},{"id": "57"}]
var input2=[{"Date": "2022-11-30","name": "salesorder","brand": "Apple","Requests": "111","price":"917.65"},{"Date": "2022-11-13","name": "orders","brand": "TV","Requests": "11","price": "91.60"}]
var input3=[{"count": "3" },{"count": "4" }]
var input4=[{"stock": "21","sold": "112"},{"stock": "2","sold": "12"}]
---
input1 map (input1[$$] ++ input2[$$] ++ input3[$$] ++ input4[$$])输出:
[
{
"id": "3857",
"Date": "2022-11-30",
"name": "salesorder",
"brand": "Apple",
"Requests": "111",
"price": "917.65",
"count": "3",
"stock": "21",
"sold": "112"
},
{
"id": "57",
"Date": "2022-11-13",
"name": "orders",
"brand": "TV",
"Requests": "11",
"price": "91.60",
"count": "4",
"stock": "2",
"sold": "12"
}
]发布于 2022-12-04 18:09:22
使用zip函数将数组组合在一起,然后使用++操作符将对象合并在一起:
(input1 zip input2) // produces an array of two element arrays
map ($[0] ++ $[1]) // combines the two elements into a single objecthttps://stackoverflow.com/questions/74660990
复制相似问题