How can I implement If-ElseIf-Else condition in Nifi
Asked Answered
A

2

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.

Anaphora answered 20/2, 2017 at 21:13 Comment(0)
G
9

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.

Germaine answered 20/2, 2017 at 21:42 Comment(0)
A
7

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.

Alister answered 8/5, 2018 at 14:4 Comment(1)
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.Cilo

© 2022 - 2024 — McMap. All rights reserved.