Arjun Arora
Arjun Arora

Reputation: 1006

JsonPath could not be found for FlowFile - SplitJson Processor - Nifi

SplitJson processor is throwing warning message when the json path does not exists. We wants to ignore this messages on our prod environment.

Example:
{"Payload":{"ProfileScores":{"scoreList":[{"Profile":"Value 1","MatchedPatternId":"Value 2"}]}}}

Now based on above json, if we use the SplitJson processor with $.Payload.ProfileScores.scoreList[*] as JsonPath Expression then everything works fine because the path is accessible.

BUT
in some cases ProfileScores object is null like this: {"Payload":{"ProfileScores":""}}.

Now as ProfileScores object is empty or null, then SplitJson throws the warning message for that particular flowfile. enter image description here

Now we want to remove those warning message as it is clogging up the logs area in prod environment.

Is there any way to check if $.Payload.ProfileScores is null/empty or exists or not before sending the flowfile to SplitJson processor?

Solutions i have tried:

  1. https://community.cloudera.com/t5/Support-Questions/Apache-nifi-Split-json-error-when-an-array-has-only-one/td-p/236040
  2. "Path not found behavior" is not available on SplitJson processor, so could not use that.

Upvotes: 0

Views: 529

Answers (1)

daggett
daggett

Reputation: 28634

here is an expression you could use:

$.Payload[?(@.ProfileScores nin [null,''])].ProfileScores.scoreList[*]

?(expression) - where

@ - current element

A nin [] - A not in array on the right

more explanation and examples here: https://github.com/json-path/JsonPath#path-examples


i used your file from question and this jsonpath works fine in nifi 1.16.3

enter image description here

Upvotes: 0

Related Questions