6

In NiFi,
I have a JSON data coming in, and I am using SplitJson and EvaluateJson to store the required components of the Json data in my own variable.

How can I implement an if-elseif-else condition on the Json data value?

For example, if attributeA==0, relationship = pass, else fail, and so on.

Bipal Shakya
  • 61
  • 1
  • 1
  • 2

2 Answers2

10

You will use the RouteOnAttribute processor with dynamic properties that evaluate the NiFi Expression Language against the provided attributes. Here are sections of the documentation on boolean operations and evaluating multiple attributes.

Paul Bendevis
  • 2,381
  • 2
  • 31
  • 42
Andy
  • 13,916
  • 1
  • 36
  • 78
5

If you want to implement an If-ElseIf-Else condition, you can do it like this:

${
LogData:jsonPath('$.email'):equals('DEV'):not():ifElse(
    ${LogData:jsonPath('$.email'):equals('QA'):ifElse(
        'aa',
        'bb'
    )},
    'cc'
)}

Note that using this approach you can create as nested conditions as you need, but if you need to do some routing it's better to use the RouteOnAttribute processor as @andy said.

Óscar Andreu
  • 1,630
  • 13
  • 32
  • Thank you for answering the actual question, even though the first answer was better for what the OP needed. This is helpful for those of us with different, but related problems. – Dave Klein Jan 24 '19 at 15:07