cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering out an Array

aditya_gupta41
Contributor

Hello Experts,

 

I have input coming in as below:

[
{
"soap:Body": {
"@xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
"ns1:searchResponse": {
"@xmlns:ns1": "http://siemens.com/agilews",
"recordmap": {
"record": [
{
"field": [
{
"key": "T_FILE_DAT.FILE_TYPE",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "ZIP"
}
},
{
"key": "T_FILE_DAT.C_ID",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "123456"
}
}
]
},
{
"field": [
{
"key": "T_FILE_DAT.FILE_TYPE",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "TIF"
}
},
{
"key": "T_FILE_DAT.C_ID",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "6789087"
}
}
]
},
{
"field": [
{
"key": "T_FILE_DAT.FILE_TYPE",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "PDF"
}
},
{
"key": "T_FILE_DAT.C_ID",
"value": {
"@xmlns:ns3": "http://siemens.com/agilews",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:type": "ns3:StringValue",
"str": "35462635"
}
}
]
}
]
}
}
}
}
]

 

The requirement is i need to pass only record containing T_FILE_DAT.FILE_TYPE.str = 'TIF'.

Also, the input from source sometimes comes out without being in an array. I want to create a solution which will work in both cases.

 

Thanks in Advance

3 REPLIES 3

koryknick
Employee
Employee

@aditya_gupta41 - so that we can best assist you, can you provide a sample of the desired output? 

Can you provide an example of some that are array and some that are not?

Hello @koryknick 

I am attaching 2 different input and their respective outputs.

Please note that the filter is suppose to happen at "T_FILE_DAT.FILE_TYPE".

I have to only pass value of T_FILE_DAT.C_ID where T_FILE_DAT.FILE_TYPE.value.str == tif or TIF

koryknick
Employee
Employee

@aditya_gupta41 - thank you for the sample data.  I believe the attached pipeline will do what you're looking for.  You will need to download, unzip, and upload the file into your org.  You can attach the Mapper and JSON Splitter to either the Single Record or Multiple Records snaps (JSON Generator) and it produces the requested output.  The first thing to understand in the Mapper is the use of the sl.ensureArray() method, which returns the argument as an array even if it isn't one... this is helpful in the next snap.  I'm also moving the xmlns:soap and xmlns:ns1 values to the root of the JSON document so they can carry through to the final output.

Next, the JSON Splitter snap will take each array element and make a new JSON document.  I'm using jsonPath() to get all "field[*]" entries across the multiple records.  Also, the "Include scalar parents" is checked to make sure we carry through the "soap" and "ns1" values to the output.

Hope this helps!