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.

NiFi: SplitJson processor with empty array

NiFi: SplitJson processor with empty array

Rising Star

When the incoming flowfile contains empty array {}, it fails with the below error. Is there a way to skip flowfile with such rows?

SplitJson[id=01581338-695c-1081-d7c3-a2b84d03b57d] The evaluated value {} of $ was not a JSON Array compatible type and cannot be split.
4 REPLIES 4

Re: NiFi: SplitJson processor with empty array

Cloudera Employee

@Kumar Looking at NiFi code here [1] and the JSON Path library [2] that it uses, both assume that the JSON contains the fields you are trying to match on. The best thing you may be able to do is to use a RouteText or RouteOnContent processor before you try and split the JSON. With either of these you can have a regex expression that tests to see if the JSON is empty and then route it accordingly. Perhaps in your use case, an empty JSON document is OK and just needs to be logged.

[1] https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-proce...

[2] https://github.com/jayway/JsonPath

Re: NiFi: SplitJson processor with empty array

Rising Star

RouteOnContent with regex (^\{\}) helped to identify the empty JSON Object.

Re: NiFi: SplitJson processor with empty array

{} is not an array, but just an empty JSON object. The array would be encoded as []. Is your incoming object always an array?

Highlighted

Re: NiFi: SplitJson processor with empty array

Rising Star

Yes, the incoming object is always an array, if there is a row. When empty, it comes as a JSON object {}

[{"dt": "2016-12-14"},{"dt": "2016-12-15"},{"dt": "2016-12-16"}]