Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

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

Highlighted

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

New Contributor

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

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

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



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

New Contributor

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



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

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

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

Super 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 :-)

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

New Contributor

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

$.[2].length()

In EvaluateJsonPath is always unmatched

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

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