Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Apache nifi - Split json error when an array has only one record or empty,

avatar
Rising Star

Apache nifi - Split json error when an array has only one record or empty,

Do you have any suggestions to fix it,

many thanks

6 REPLIES 6

avatar
Master Guru

@Thuy Le

Use EvaluateJsonPath processor and add new property to determine length of the array.

109948-screen-shot-2019-07-21-at-110621-pm.png

Then use RouteOnAttribute processor to check the array_length attribute value and route to SplitJson processor or some other processor.

Flow:

--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..



avatar
Rising Star

thanks @Shu, It doesnot work with when empty json

109982-1563825176018.png


109967-1563825213198.png
109955-1563825247529.png

and also nested json

109981-1563825151734.png



avatar
Master Guru

@Thuy Le

If you have array then configure EvaluateJson processor and add new property as

$.[2].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.

avatar
Master Guru

@Thuy Le

If the answer is helpful to resolve the issue, Login and Click on Accept button below to close this thread.This will help other community users to find answers quickly 🙂

avatar
Rising Star

Sorry, but It dose not work in my side. I guess that you didnot test it

$.[2].length()

In EvaluateJsonPath is always unmatched

avatar
New Contributor

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.

regards,

titaniumtv download