Support Questions
Find answers, ask questions, and share your expertise

Nifi Expression language ifelse in ReplaceText processor

Solved Go to solution
Highlighted

Nifi Expression language ifelse in ReplaceText processor

Hi All,

 

I am trying to build JSON string using Ifelse condition in ReplaText processor but i am getting error as invalid Invalid Expression .

 

Working Ifelse condition : 

${status:contains('0'):ifElse('Success','Failed')}Invalid_Expression.PNG

 

This below string is not working and it is throwing invalid expression . Please assist on this .

 

${status:contains('0'):ifElse('{
"filename":"${overall_filename}",
"status":"${status}",
"message":"${overall_message}"
}',
'{
"filename":"${overall_filename}",
"status":"${exc_status}",
"message":"${overall_message}"
}'
)
}

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Nifi Expression language ifelse in ReplaceText processor

Master Guru

@adhishankarit 
The issues is being caused by the line returns used in the middle of the NiFi NiFiExpression Language (EL) ifElse() function you are using.

The text box where you enter your NiFi EL uses a NiFi editor that highlights to show proper EL format.  You'll notice your EL stops highlighting once you reach first line return. So you'll notice character 32 is the first single quote character.  Since EL breaks at this point it fails to find the matching second expected single quote.

Screen Shot 2021-01-25 at 9.14.52 AM.png


This leaves you with two options:
1. Create flat json without the line returns.
2. Looking at result you are trying to achieve, design your NiFi EL differently:
Screen Shot 2021-01-25 at 9.17.48 AM.png
Note proper NiFi EL highlighting above.


Hope this helps,
Matt

View solution in original post

1 REPLY 1

Re: Nifi Expression language ifelse in ReplaceText processor

Master Guru

@adhishankarit 
The issues is being caused by the line returns used in the middle of the NiFi NiFiExpression Language (EL) ifElse() function you are using.

The text box where you enter your NiFi EL uses a NiFi editor that highlights to show proper EL format.  You'll notice your EL stops highlighting once you reach first line return. So you'll notice character 32 is the first single quote character.  Since EL breaks at this point it fails to find the matching second expected single quote.

Screen Shot 2021-01-25 at 9.14.52 AM.png


This leaves you with two options:
1. Create flat json without the line returns.
2. Looking at result you are trying to achieve, design your NiFi EL differently:
Screen Shot 2021-01-25 at 9.17.48 AM.png
Note proper NiFi EL highlighting above.


Hope this helps,
Matt

View solution in original post