I would like to map a json, based on some nested attribute, but somehow there seems to be a stupid mistake I make.
My input:
[
{
"productNo": "00011111",
"items": [
{
"color": "000000000006000060",
},
{
"color": "000000000006000061",
}
]
},
{
"productNo": "00022222",
"items": [
{
"color": "000000000006000060"
},
{
"color": "000000000006000061"
}
]
}
]
My transformation:
%dw 2.2
output application/json
---
payload map ( prod , indexOfProd ) -> {
(prod.items map (prodItem, indexOfProdItem) -> {
PNR: prod.productNo,
Color: color.quantity
})
}
My result:
[
{
"PNR": 00011111,
"Color": "000000000006000060",
"PNR": 00011111,
"Color": "000000000006000061"
},
{
"PNR": 00022222,
"Color": "000000000006000060",
"PNR": 00022222,
"Color": "000000000006000061"
}
]
My expected result / What I'm trying to get:
[
{
"PNR": 00011111,
"Color": "000000000006000060"
},
{
"PNR": 00011111,
"Color": "000000000006000061"
},
{
"PNR": 00022222,
"Color": "000000000006000060"
},
{
"PNR": 00022222,
"Color": "000000000006000061"
}
]
Any hint why it's not separating the results based on the color variations?
You can use the following dataweave expression: