Forum Discussion
dimitri_hristov
6 years agoContributor
Hi @vaidyarm,
I assumed that you have both arrays, $REFILL and $TOTLITEM, in the same input document. Then, putting this expression in a Mapper:
$TOTLITEM.item.map((item, pos, a)=>item.extend({WORK: $REFILL.item[pos].WORK}))
and assigning it to the $TOTLITEM.item Target Path, should do what you need done.
BR,
Dimitri
That was quick and awesome, many thanks !! this gives an idea for all such type of transformations.
can you also suggest a solution for a case like below,
where the number of elements to be mapped subsection of the array does not matches the count of source array.
For the same input as above, below is expected output.
[
{
"REFILL":{
"item":[
{
"ITEM":"1",
"TEXT":"first",
"NAME":"laptop",
"WORK":"office"
},
{
"ITEM":"2",
"TEXT":"second",
"NAME":"mobile",
"WORK":"marketing"
}
]
}
},
{
"TOTLITEM":{
"item":[
{
"ITEM":"1",
"TEXT":"first",
"NAME":"none",
"DETAILS":[
{
"LINE":"1",
"WORK":"office"
},
{
"LINE":"2",
"WORK":"office"
}
]
},
{
"ITEM":"2",
"TEXT":"second",
"NAME":"none",
"DETAILS":[
{
"LINE":"1",
"WORK":"marketing"
}
]
}
]
}
}
]
being able to do this, will help a lot to handle any transformation thereafter. let me know the solution.