Created on 03-06-2022 12:20 PM - edited 03-06-2022 08:15 PM
I have a nested json with few first level keys. I want to compare two keys before and after in that json to see if the states are matching or not. If the states match then route to update api else insert api.
What I have tried so far : getfile-->evaluate json path(to get the two keys before and after)-->route on attributes
Now my problem is that route on attributes always evaluates to unmatched even if the values in eval json path for before and after are the same.
Expression : Eval json path 1 : a_before = $.['a']['before'][*]['ip']
Eval json path 2 : a_after = $.['a']['after'][*]['ip']
Above results in the same ip - ["1.0.0.0"]
RouteOnAttribute : ${a_after:equals(${a_before})}
This always results in an unmatched even if the records match.
Any help will be appreciated.
Created 03-06-2022 11:41 PM
Hi @Olivia_4692 ,
The only issue I can see here is that in your sample data "Before" has a capital B, while you your EvaluateJSONPath configuration it's all in lowercase. This will certainly create a problem for your logic.
I tried your data (converting "Before" to "before") and it worked correctly in my test.
Please my test flow attached.
Cheers,
André
--
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Created 03-06-2022 02:33 PM
Your approach is correct and it should work as you expect.
There are a few things that I'd like to check, though:
1. In the JSON Path expression "a_before = $.['a']['before'][]['ip']", what's the reason for the empty "[]" just before "['ip']"? Could you please share a sample of your data?
2. Have you checked for leading or trailing spaces in either one of the attributes?
3. This is probably a copy&paste mistake, but I noticed that your RouteOnAttribute expression is missing a "}" at the very end.
Cheers,
Andre
--
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Created on 03-06-2022 08:02 PM - edited 03-06-2022 08:16 PM
Hi Andre,
thank you for your answer.
1. The empty [] is actually [*] because that value keeps changing. It think that did not get copied.
2.I’ve checked for space and there are none
3. Yes thank you for pointing that out. And sorry about that. I was a copy paste mistake.
I've just edited my OP.
Created 03-06-2022 08:49 PM
Would you have a sample of the input data?
André
Created on 03-06-2022 09:58 PM - edited 03-06-2022 11:24 PM
Sample input data :
“a”:{
“after”:{
“a123”:{
“ip”:”1.0.0.0”,
“series”:”4500”
}
},
“Before”:{
“a123”:{
“ip”:”1.0.0.0”,
“series”:”4500
}
}
}
Created 03-06-2022 11:41 PM
Hi @Olivia_4692 ,
The only issue I can see here is that in your sample data "Before" has a capital B, while you your EvaluateJSONPath configuration it's all in lowercase. This will certainly create a problem for your logic.
I tried your data (converting "Before" to "before") and it worked correctly in my test.
Please my test flow attached.
Cheers,
André
--
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Created 03-07-2022 01:12 AM
Hi @araujo - you've attached a text file. How do I import that as a template? If you could attach your flow as an xml file that would be helpful.
Created 03-07-2022 01:26 AM
@araujo - thank you so much. I referred to the same flow file you have attached. It works perfectly. The problem with mine was I was using two eval json processors and route on attributes wasn't able to compare from two different flowfiles.