โ05-31-2023 11:11 AM
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.
โ05-31-2023 12:23 PM
Hello @sravan,
In order to achieve the wanted transformations you can use two Mapper Snaps.
The first one with Mapping Root set to $cover[*] and mapping the elements of the cover array.
And the second Mapper to rename the cover array to ppCover.
Also, here is a sample pipeline:
sl-comm-transform-array_2023_05_31.slp (6.2 KB)
Try this out, and let me know if this helps you.
BR,
Aleksandar.
โ05-31-2023 12:33 PM
Or you can use the following map function in one Mapper Snap:
$cover.map(x => {
"needCode":x.needCode,
"needKindName":x.needKindName,
"rates": x.hasPath("coverAmount") ? [{
"type":"Cover Amount",
"amount":{
"value":x.coverAmount.amount,
"currencyCode":x.coverAmount.currencyCode.toLowerCase()
}
}] : []
})
If you ask me, I would suggest going with the first approach if possible, since it is cleaner and easier to maintain.
Try both ways and let me know.
โ05-31-2023 07:07 PM
Both Works.The first method is kind of hard coded one. We need to lookup on coveraount. it yes we need to proceed else create a empty array. Second one is working fine for me. I appreciate your help in this regards
โ06-01-2023 07:35 AM
actually this works only if we have covers. I got into another problem now. I am pasting INPUT and OUTPUT here. could you please on how we can transform this. I used json generator to transform but no luck.
@AleksandarAngelevski
INPUT:
{
โsummaryโ: {
โairtimeEnabledInsuranceProductCodeโ: {
โcoverโ: [
{
โneedCodeโ: โIllnessโ,
โneedKindNameโ: โHospital Illnessโ,
โautoBoostCoverAmountโ: {
โamountโ: 25,
โcurrencyCodeโ: โXAFโ
},
โcoverAmountโ: {
โamountโ: 0,
โcurrencyCodeโ: โXAFโ
}
},
{
โneedCodeโ: โAccidentโ,
โneedKindNameโ: โHospital Accidentโ,
โautoBoostCoverAmountโ: {
โamountโ: 25,
โcurrencyCodeโ: โXAFโ
},
โcoverAmountโ: {
โamountโ: 0,
โcurrencyCodeโ: โXAFโ
}
},
{
โneedCodeโ: โLifeโ,
โneedKindNameโ: โLifeโ,
โautoBoostCoverAmountโ: {
โamountโ: 25,
โcurrencyCodeโ: โXAFโ
},
โcoverAmountโ: {
โamountโ: 0,
โcurrencyCodeโ: โXAFโ
}
}
],
โpolicyNumberโ: โ1234567โ,
โpolicyStatusโ: โNot Taken Upโ,
โproductCodeโ: โAirtime Enabledโ,
โcoverAmountSegmentsโ: [
{
โstartDateโ:โ2022-03-20T00:00:00โ,
โendDateโ:โ2022-09-19T00:00:00โ,
โsumAssuredโ:{
โamountโ:10000.0,
โcurrencyCodeโ:โXAFโ
}
},
{
โstartDateโ:โ2022-03-20T00:00:00โ,
โendDateโ:โ2022-09-19T00:00:00โ,
โsumAssuredโ:{
โamountโ:5000.0,
โcurrencyCodeโ:โXAFโ
}
}],
โcoverStatusโ: {
โloyaltyโ: โACTIVEโ,
โautoBoostโ: โACTIVEโ,
โprepaidโ: โACTIVEโ
}
},
โbonusAmountโ: {
โamountโ: 2.50,
โcurrencyCodeโ: โGHSโ
},
โbonusAmountRequiredToConvertโ: {
โamountโ: -155.50,
โcurrencyCodeโ: โXAFโ
},
โconsentsโ: [
{
โagreementReferenceโ: โ0006978665โ,
โcontentโ: โRecharge With Careโ,
โreferenceโ: โ2150000059599412โ,
โresponseโ: โNO-RESPONSEโ,
โtypeโ: โRecharge With Care Policy Changeโ
}
],
โmemberIdโ: โ2320000000000โ,
โkycInfoโ: {
โkycStatusโ: true,
โkycConfirmationโ: false
},
โlanguageโ: โEnglishโ
}
}
OUTPUT:
{
โproductsโ: [
{
โtypeโ: โaYo Airtime Enabledโ,
โpolicyNumberโ: โ1234567โ,
โpolicyStatusโ: โNot Taken Upโ,
โattributesโ: [
{
โnameโ: โGame Levelโ,
โvalueโ: โ1โ
}
],
โpostPaidCoverโ: [
{
โneedCodeโ: โIllnessโ,
โneedKindNameโ: โHospital Illnessโ,
โratesโ: [
{
โtypeโ: โautoBoostCoverAmountโ,
โamountโ: {
โvalueโ: 25,
โcurrencyCodeโ: โXAFโ
}
},
{
โtypeโ: โCover Amountโ,
โamountโ: {
โvalueโ: 0.00,
โcurrencyCodeโ: โXAFโ
}
}
]
},
{
โneedCodeโ: โAccidentโ,
โneedKindNameโ: โHospital Accidentโ,
โratesโ: [
{
โtypeโ: โautoBoostCoverAmountโ,
โamountโ: {
โvalueโ: 25,
โcurrencyCodeโ: โXAFโ
}
},
{
โtypeโ: โCover Amountโ,
โamountโ: {
โvalueโ: 0.00,
โcurrencyCodeโ: โXAFโ
}
}
]
},
{
โneedCodeโ: โLifeโ,
โneedKindNameโ: โLifeโ,
โratesโ: [
{
โtypeโ: โautoBoostCoverAmountโ,
โamountโ: {
โvalueโ: 25,
โcurrencyCodeโ: โXAFโ
}
},
{
โtypeโ: โCover Amountโ,
โamountโ: {
โvalueโ: 0.00,
โcurrencyCodeโ: โXAFโ
}
}
]
}
],
โprepaidCoverโ: [
{
โstartDateโ: โ2022-03-20T00:00:00โ,
โendDateโ: โ2022-09-19T00:00:00โ,
โamountโ: {
โvalueโ: 100000.0,
โcurrencyCodeโ: โGHSโ
}
}
]
}
],
โconsentsโ: [
{
โagreementReferenceโ: โ0006978665โ,
โcontentโ: โRecharge With Careโ,
โreferenceโ: โ2150000059599412โ,
โresponseโ: โNO-RESPONSEโ,
โtypeโ: โRecharge With Care Policy Changeโ
}
],
โbonusโ: [
{
โtypeโ: โbonusAmountโ,
โamountโ: 2.50,
โcurrencyCodeโ: โGHSโ
},
{
โtypeโ: โrequiredToConvertโ,
โamountโ: -155.50,
โcurrencyCodeโ: โGHSโ
}
],
โmemberIdโ: โ2320000000000โ,
โkycInfoโ: {
โkycStatusโ: true,
โkycConfirmationโ: false
},
โlanguageโ: โEnglishโ
}