Support Questions

Find answers, ask questions, and share your expertise

How to perform if-else operation in Apche Nifi

Explorer

I have a use case where I have couple of key values and perform if-else operation on it. If condition is not matched then whole content will drop, else pass the content as a result.

 

Input json:

{
  "id": 30006,
  "SourceName": "network",
  "Number": 1,
  "SourceNameCopy": "network",
  "currenttime": "Thu Aug 30 21:19:27 IST 2022"
}

My Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "SourceNameCopy": {
        "network": {
          "@1": "&2",
          "#id": "id",
          "#SourceName": "SourceName",
          "#Number": "Number",
          "#currenttime": "currenttime"
        },
        "hardware": {
          "@1": "&2",
          "#id": "id",
          "#SourceName": "SourceName",
          "#Number": "Number",
          "#currenttime": "currenttime"
        }
      }
    }
  }
    ]

Expected output

if condition matched :

{
  "id": 30006,
  "SourceName": "network",
  "Number": 1,
  "SourceNameCopy": "network",
  "currenttime": "Thu Aug 30 21:19:27 IST 2022"
}

Else (condition not matched) Drop the whole event as null.
Problem Statement : The Key values is getting as a string, it should contain actual value in output as a result.

1 REPLY 1

Super Collaborator

Hi ,

 

where is the key,value pair are stored? Are they stored as a flowfile attribute or in the input json? there are processors like RouteOnAttribute in case they are stored as attributes where you can create your condition as dynamic property and provide the logical expression there. If the key\value pair is part of the json you can use Extract Text to Extract the key\value pair as an attribute then use RouteOnAttribute or you can try to use RouteOnContent if that will work?

 

If you find this helpful, please accept solution. Thanks

Samer

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.