Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Nifi Expression language ifelse in ReplaceText processor

avatar
Contributor

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

avatar
Master Mentor

@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

avatar
Master Mentor

@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