cancel
Showing results for 
Search instead for 
Did you mean: 

Replacing Fields which are in List of Objects

GBekkanti
New Contributor III

Hi Team,

I have a requirement to replace the fields which are in list of objects. Please find the details below:

Please find the input JSON below:
listValueCommunityedited

I need to replace the CurrencyCode value from 2nd highlighted to 1st highlighted (i.e. INR to IndianRupee and AUD to AustralianDollar). Remaining fields in 1st highlighter should remain as is.

Thanks in Advance! Quick help is highly appreciated.
Gopi.

6 REPLIES 6

tstack
Former Employee

Are you expecting to process $shoppingHistoryList.shoppingHistory on its own or are you merging it with $input1_shoppingHistoryList.shoppingHistory where each element in $shoppingHistoryList corresponds to an element in $input1_shoppingHistoryList?

GBekkanti
New Contributor III

Thank you @tstack for the reply, I need to merge with $input1_shoppingHistoryList.shoppingHistory where each element in $shoppingHistoryList corresponds to an element in $input1_shoppingHistoryList but, the remaining fields in ‘$shoppingHistoryList.shoppingHistory’ should not be changed.

You can do this with the expression language inside of a Mapper. For merging the arrays, you can use the sl.zip() function, like so:

sl.zip($shoppingHistoryList.shoppingHistory, $input1_shoppingHistoryList.shoppingHistory)

The result of that expression will be an array of pairs containing the element from the first array and the corresponding element from the second array. Once they are grouped together, you can use a map() method on the array to iterate over the pairs and then use extend() method to update the properties in the element from the first array with properties from the element in the second:

sl.zip($shoppingHistoryList.shoppingHistory, $input1_shoppingHistoryList.shoppingHistory).map(x => x[0].extend(x[1]))

Here’s an example pipeline that does this mapping:

ReplaceFields_2018_12_16.slp (5.7 KB)

GBekkanti
New Contributor III

A Very Big Thanks @tstack