Creating one more field in list of objects by using the fields in same objects

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!

Use a mapper, pass existing fields through, and create a new field $halfAge = $Age / 2

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:
mapperView

Can you please process now?

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:

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?

One of the functions available in the expression language is zip, which enables you to merge two arrays. Does this help?

@GBekkanti

sounds like you want to do something like this which you can do using sl.zip()

sl.zip($items, $genderArray).map(pair => pair[0].extend({ Gender: pair[1] }))

Thanks @cjhoward18, @cstewart

It works fine. Thank you