09-18-2023 01:57 AM
Hello everyone,
I have a json that looks like the bellow and I want to filter the $input0 data by whatever key/values exists in $filterData in the end. The $filterData may have ID or Customer (in this example it has ID). I have tried in Mapper with filter() and in Filter Snap, I did not have any success. Can someone help or had to solve something similar?
[
{
"input0": [
{
"ID": "1",
"CUSTOMER": "a"
},
{
"ID_NUMERIC": "2",
"CUSTOMER": "b"
},
{
"ID": "1",
"CUSTOMER": "c"
},
{
"ID": "3",
"CUSTOMER": "d"
},
{
"ID": "4",
"CUSTOMER": "f"
},
{
"ID": "4",
"CUSTOMER": "b"
}
],
"filterData": [
{
"ID": "1"
},
{
"ID": "2"
}
]
}
]
The output should contain both ID and Customer values, just like the $input0 but filtered.
Solved! Go to Solution.
09-19-2023 11:52 PM
@vfantidou Please use below expression-. From your example seems there are some typo (2nd record in input0 should have ID not ID_NUMERIC). If it's not typo you need make null safe in mapper.
input0.filter((val,index)=> $filterData.find((ele)=> ele['ID'] ==val['ID'] ) != null )
09-18-2023 07:28 AM
Try this expression:
$input0.filter((elem) => $filterData.find(x => elem.ID == x.ID))
09-18-2023 07:49 AM
09-18-2023 08:43 AM
Try with this expression:
$input0.filter((elem) => $filterData.find(x => elem.ID == x.ID))
09-19-2023 02:10 AM
Try with below expression:
$input0.filter((elem) => $filterData.find(x => elem.ID == x.ID))