cancel
Showing results for 
Search instead for 
Did you mean: 

Add key to array of objects

Max
New Contributor II

Hello,

I have an array of objects that i need to simply add a key to. However, im not a able to find a way of doing this. attached are screen shots of the input and desired output. Any advise is much appreciated.

Input:

[
{
fromCurrency:{
code: "CUC",
name: "Cuban convertible peso"
},
toCurrency:{
code: "CLP",
name: "Chilean peso"
},
balanceSheetRate: 672.98,
exchangeRate: 670.894,
lastUpdatedDate: "2021-05-20",
effectiveDate: "20231201184413"
},
{
fromCurrency:{
code: "BTC",
name: "Bitcoin"
},
toCurrency:{
code: "MTL",
name: "Maltese lira"
},
balanceSheetRate: 0.91050133,
exchangeRate: 0.93682458,
lastUpdatedDate: "2021-05-19",
effectiveDate: "20231201184413"
}]
 
Desired output:
{
"exchangeRates": [
{
"fromCurrency": {
"code": "TWD",
"name": "New Taiwan dollar"
},
"toCurrency": {
"code": "AZN",
"name": "Azerbaijani manat"
},
"exchangeRate": 0.05271961,
"balanceSheetRate": 0.05239825,
"lastUpdateDate": "2023-11-02",
"effectiveDate": "20231201184413"
},
{
"fromCurrency": {
"code": "YER",
"name": "Yemeni rial"
},
"toCurrency": {
"code": "CDF",
"name": "Congolese franc"
},
"exchangeRate": 9.96723124,
"balanceSheetRate": 10.30493871,
"lastUpdateDate": "2023-11-02",
"effectiveDate": "20231201184413"
}]

 

3 REPLIES 3

koryknick
Employee
Employee

@Max - The simplest way that I can think to accomplish what you're asking for is to use a Gate snap with the default settings and rename the input view to "exchangeRates" as below:

koryknick_0-1701523494993.png

A word of caution on the Gate snap with the default settings - this snap consumes all input into a single document, which may consume significant memory resources if processing a large volume of data.

Hope this helps!

 

Max
New Contributor II

@koryknick- The gate snap worked in this use case. However, it is concerning that it may have resource issues if processing large data. The data set in this case is around 35K records. But we have a lot of cases this logic will need to be used and our datasets are huge. Is there a better way/more efficient way of doing this with big result sets? 

koryknick
Employee
Employee

It depends on the use case.  You can use the Structure or Mapper snaps to manipulate individual input JSON documents, or use Group By Fields or Gate snaps to accumulate JSON documents into arrays.

SnapLogic is well suited to work with large data sets, you just need to think about how it is being processed and whether or not you need to accumulate everything into large, nested JSON documents for your endpoint.