Forum Discussion

sravan's avatar
sravan
New Contributor II
3 years ago

Transform Array to New array

I have a requirement where I need to convert an array into new array . Below is the example .

INPUT:

{
“cover”: [
{
“needCode”: “abc”,
“needKindName”: “abc xyz”,
“autoBoostCoverAmount”: {
“amount”: 25,
“currencyCode”: “XAF”
},
“coverAmount”: {
“amount”: 0,
“currencyCode”: “XAF”
}
},
{
“needCode”: “ttt”,
“needKindName”: “abc ttt”,
“autoBoostCoverAmount”: {
“amount”: 25,
“currencyCode”: “XAF”
},
“coverAmount”: {
“amount”: 0,
“currencyCode”: “XAF”
}
},
{
“needCode”: “rrr”,
“needKindName”: “abc rrr”,
“autoBoostCoverAmount”: {
“amount”: 25,
“currencyCode”: “XAF”
},
“coverAmount”: {
“amount”: 0,
“currencyCode”: “XAF”
}
}
]
}

OUTPUT

{
“ppCover”: [
{
“needCode”: “abc”,
“needKindName”: “abc xyz”,
“rates”: [
{
“type”: “Cover Amount”,
“amount”: {
“value”: 0.00,
“currencyCode”: “xaf”
}
}
]
},
{
“needCode”: “ttt”,
“needKindName”: “abc ttt”,
“rates”: [
{
“type”: “Cover Amount”,
“amount”: {
“value”: 0.00,
“currencyCode”: “xaf”
}
}
]
},
{
“needCode”: “rrr”,
“needKindName”: “abc rrr”,
“rates”: [
{
“type”: “Cover Amount”,
“amount”: {
“value”: 0.00,
“currencyCode”: “xaf”
}
}
]
}
]
}

Step 1: Cover needs to be renamed as “ppCover”
Step2: Create a new array of objects called rates inside ppcover array .
Step3: field type inside the rates array is “coverAmount” as we have the coverAmount object in Input .if there is no coverObject in the input then it should be empty

please help how we can manage this using map function.

@bojanvelevski In case if you could help us.