โ05-06-2019 05:43 AM
Hi Team,
I have the below input data :
[
{
ID:123
โNameโ:โTonyโ,
โAgeโ:24
},
{
ID:124
โNameโ:โSamโ,
โAgeโ:36
},
{
ID:125
โNameโ:โGlennโ,
โAgeโ:58
}]
I need to add one more field โhalfAgeโ to the above and output data should be like below:
[
{
ID:123
โNameโ:โTonyโ,
โAgeโ:24,
โhalfAgeโ:12
},
{
ID:124
โNameโ:โSamโ,
โAgeโ:36
โhalfAgeโ:18
},
{
ID:125
โNameโ:โGlennโ,
โAgeโ:58,
โhalfAgeโ:29
}]
Can you please let me know the Expression language for this?
Thanks in Advance!
โ05-06-2019 06:09 AM
Use a mapper, pass existing fields through, and create a new field $halfAge = $Age / 2
โ05-06-2019 07:45 AM
Sorry for my wrong input structure. the below is the correct one. It is a list of objects rather than 3 single objects
{โitemsโ:[
{
โIDโ:123,
โNameโ:โTonyโ,
โAgeโ:24
},
{
โIDโ:124,
โNameโ:โSamโ,
โAgeโ:36
},
{
โIDโ:125,
โNameโ:โGlennโ,
โAgeโ:58
}]}
and the view in mapper is like below:
Can you please process now?
โ05-06-2019 09:02 AM
Since youโre manipulating an array, youโll want to look into the โMapping Rootโ feature of the Mapper. By pointing the Mapping Root at your array, the Transformations will be applied to the elements of the array instead of the top-level document. Otherwise, the Mapper configuration is the same as suggested by @christwr:
โ05-06-2019 08:33 PM
Thanks for your reply @tstack and @christwr,
I have one more array in input like below
โgenderArrayโ:[โMaleโ,โFemaleโ,โMaleโ]
Now, I need to add the corresponding values to the objects of itemsโ array by creating new โGenderโ field.
output should be like below:
{โitemsโ:[
{
โIDโ:123,
โNameโ:โTonyโ,
โAgeโ:24,
โGenderโ:โMaleโ
},
{
โIDโ:124,
โNameโ:โSamโ,
โAgeโ:36,
โGenderโ:โFemaleโ
},
{
โIDโ:125,
โNameโ:โGlennโ,
โAgeโ:58,
โGenderโ:โMaleโ
}]}
Can you please let me know the process?