Apache nifi - Split json error when an array has only one record or empty,
Do you have any suggestions to fix it,
Use EvaluateJsonPath processor and add new property to determine length of the array.
Then use RouteOnAttribute processor to check the array_length attribute value and route to SplitJson processor or some other processor.
--other processors EvaluateJsonProcessor //add array_length property to the processor RouteOnAttribute //add dynamic properties to check the array_length attribute value. |split ---------------------------------------------- |(array_length more than 2) |(array_length less than 2) SplitJson Some other processors..
If you have array then configure EvaluateJson processor and add new property as
$..length() //means if you have 2 json objects in array then attribute value will be 1 else empty.
Then by using RouteOnAttribute processor check if the value is empty or 1 and route the flowfile accordingly.
2.What if there is empty json data?
Still processor adds length attribute value as Empty String Set and in RouteOnAttribute processor you can check the value is Empty or not.
Another way of checking will be by using RouteText processor and check is there any data in the flowfile content by adding Regular expression dynamic property in RouteText processor.
Sorry, but It dose not work in my side. I guess that you didnot test it
In EvaluateJsonPath is always unmatched
Splits a JSON File into multiple, separate FlowFiles for an array element specified by a JsonPath expression. Each generated FlowFile is comprised of an element of the specified array and transferred to relationship 'split,' with the original file transferred to the 'original' relationship. If the specified JsonPath is not found or does not evaluate to an array element, the original file is routed to 'failure' and no files are generated.