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!
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.
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!
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:
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 :))
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