- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Apache nifi - Split json error when an array has only one record or empty,
- Labels:
-
Apache NiFi
Created ‎07-21-2019 02:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apache nifi - Split json error when an array has only one record or empty,
Do you have any suggestions to fix it,
many thanks
Created on ‎07-22-2019 04:17 AM - edited ‎08-17-2019 04:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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..
Created on ‎07-22-2019 07:54 PM - edited ‎08-17-2019 04:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Created ‎07-23-2019 01:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Created ‎07-25-2019 03:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
Created ‎07-25-2019 12:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, but It dose not work in my side. I guess that you didnot test it
$.[2].length()
In EvaluateJsonPath is always unmatched
Created ‎07-25-2019 03:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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,
