02-10-2023 01:58 PM
Hi there
I have following json
[
{
"quantity": [
"3.0",
"4.0",
"2.0"
],
"order-header-id": [
"16737",
"16737",
"16737",
],
"line-num": [
"1",
"2",
"3",
],
"coupalineAttacments": [
{
"id": {
"@type": "integer",
"$": "1878040"
},
"text": "OIL"
},
{
"id": {
"@type": "integer",
"$": "1878042"
},
"text": "SURGE TRAP "
}
]
}
]
that I need to convert it into multiple records based on line-num
[
{
"quantity" : "3.0",
"order-header-id": "16737",
"line-num": "1",
"coupalineAttacments":
{
"id": {
"@type": "integer",
"$": "1878040"
},
"text": "OIL"
}
}
{
"quantity" : "4.0",
"order-header-id": "16737",
"line-num": "2",
"coupalineAttacments":
{
"id": {
"@type": "integer",
"$": "1878042"
},
"text": "SURGE TRAP "
}
}
{
"quantity" : "2.0",
"order-header-id": "16737",
"line-num": "3",
"coupalineAttacments": ""
}
]
I have tried mapValues also map but doesnt look I am doing right. any guidance.
thanks
Manohar
02-13-2023 12:27 AM
Hello @manohar,
The following expression should do the job:
sl.range(0, $quantity.length).map( x => $.mapValues(v => x < v.length ? v[x] : ""))
Let me know if this helps you.
BR,
Aleksandar.
02-15-2023 03:14 PM
Hi @AleksandarAngelevski, thank you very much. that helped.
Manohar