Created 07-30-2018 11:01 AM
Hello everybody. In order to use a JOLT specification, I need to check ,inside my JSON, if a specific key is an Array or an Object and then route on an attribute, to be set after the validation. I tried different ways, through json path evaluators, attributes and so on and came to the conclusion that the only right way to do it is by executing a script, right? Has someone ever come across the same problem? If yes, could you provide some examples? Thanks!
Created 07-31-2018 09:34 PM
I assume this is being done in Nifi? (I would add the Apache-Nifi tag if so)
If you know the structure of the JSON object that you will be receiving, you can use an evaluateJSONPath processor to pull the JSON key's value into a flowfile attribute. Then an updateAttribute processor where you use Nifi expression language's 'equals' to determine if the value is as you expected.
https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#equals
The output of updateAttribute will be true or false and you can pass that to your routeOnAttribute processor.
I hope this helps or gives you some ideas!
Created 08-01-2018 03:15 PM
thanks for your answer but I don't think it would resolve my problem. I know the JSON structure except for one of the objects.
I'm facing 2 different situations, I'll make an example in pseudo-language:
1) "key":[{obj},{obj}...{obj}]
2) "key":{obj}
I wasn't able to produce a proper JOLT spec, cause I need to loop inside the array in case 1).
I was able to find a different solution though.
Using an ExecuteScript processor and an ECMAScript (using Array.isArray()) then setting a proper attribute in the Flowfile, then routing to different JOLT spec, I'm able to handle case 1) an 2) separately.
This is actually working pretty well but I'm still wondering if I could handle the 2 cases inside one JOLT spec.
(I edited the tags, sorry :))
Created 08-01-2018 04:32 PM
No problem on the tags, I just wanted to ensure you got some traffic on this!
I had never looked into JOLT before now, this is some pretty cool stuff! I'll look into it and maybe I'll be able to come up with something for you. Sounds like you have got your minimum viable product for now though:P
Created on 12-04-2018 02:04 PM - edited 08-17-2019 10:31 PM
I have used "RouteOnContent" and it works fine:
Created 04-25-2019 12:50 PM
This is a great solution! Makes it very easy for others to follow exactly what is happening!