I posted here about a merge expression I was attempting to get working and received an answer. However, I notice that the match expression includes all records for Obj1 regardless of whether there is a matching key or not. I only want to return records that match and return no records in the output that don't match on the key.
I have read up on the filter function and tried to apply it to this scenario but it is not working. I also tried chatGPT and it also gave a answer that is invalid, according to JSONata.org and the test function on the change node, "Expected ")", got ";""
Input:
{"payload":[
{
"Obj1": [
{
"Datetime": "2020-04-03 01:21:07.650",
"ID": "00001",
"code": "WAXXNNNX"
},
{
"Datetime": "2020-04-03 01:21:07.650",
"ID": "00002",
"code": "CAXXNNNX"
}
]
},
{
"Obj2": [
{
"X102": "Y",
"X116": "N",
"X435": "00001"
},
{
"X102": "Y",
"X116": "Y",
"X435": "00002"
}
]
}
]}
Expression:
$$.payload[0].Obj1[$filter(Obj1,
$Obj2 := $$.payload[1].Obj2[$.X435 = $.ID];
$Obj2 != null
).(
{
'ID': $.ID,
'Datetime': $.Datetime,
'Code': $.code,
'X102_ZipSuffixFlag': $Obj2.X102,
'X116_TerminationIDFlag': $Obj2.X116
}
)]
Any help is appreciated, thanks!