cancel
Showing results for 
Search instead for 
Did you mean: 

Create Key: Pair value in mapper

akarsh
New Contributor III
Input Structure
[
{
"Id": "ABC",
"IFA_Number__c": "1"
},
{
"Id": "BCD",
"IFA_Number__c": "2"
}
]

I have to save this data in a key value format ( Ifanumber is key and ID is value) so that later in mapper I have to fetc fetch the respective ID based on IFA number. what's best way to do this?

2 ACCEPTED SOLUTIONS

Hello @akarsh,

You can try with grouping all of the documents into a single array, then using reduce to combine them in one object.

Please note that if you have duplicate keys through the documents, they will overwrite.

Please refer to the attached pipeline and let me know if this helps you.

 

Regards,

Aleksandar.

View solution in original post

You can try with the following expression:

$dataList.map(x => x.get('IfaNumber',null)).filter((x,ind,arr) => x != null && arr.indexOf(x) == ind)

Let me know if this helps.

Regards,

Aleksandar.

View solution in original post

11 REPLIES 11

akarsh
New Contributor III

Thanks a lot, it worked. 

akarsh
New Contributor III

@Aleksandar_A  there is a possibility that IcustomerIFANumber might not be present . is there a way to skip the mapping when its not present? 
$dataList.map(x => x.customerIFANumber != null ? x.customerIFANumber : null).filter((x,ind,arr) => arr.indexOf(x) == ind).toString()

Hello @akarsh,

Could you please share an example of your input and the expected output?

akarsh
New Contributor III

Sorry I posted the question in wrong thread.

input will be like this

{
"totalCount": 4,
"dataList": [
{
"IfaNumber": "1",
"alink": "",
"agroupId": ""
},
{
"IfaNumber": "2",
"alink": "",
"agroupId": ""
},
{
"IfaNumber": "3",
"alink": "",
"agroupId": ""
},
{
"alink": "",
"agroupId": ""
}
]
}


Output
["1","2",3"]


this question


https://community.snaplogic.com/t5/designing-and-running-pipelines/filter-single-attribute-from-json...

You can try with the following expression:

$dataList.map(x => x.get('IfaNumber',null)).filter((x,ind,arr) => x != null && arr.indexOf(x) == ind)

Let me know if this helps.

Regards,

Aleksandar.