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 JSON event extraction only integers from string

avatar
Explorer

I have a JSON data coming as {"x":"avc123.abc.com"} I would like to have a processor in nifi to extract only the integer (123) from the entire value and output it from the process

secondly, I would like that integer value (123) to be added in the JSON event with different keys such as the final JSON event would be {"x":"avc123.abc.com" "y":"123" }

I already tried routetext and extract text but it didn't work.

2 ACCEPTED SOLUTIONS

avatar
Master Guru

@ANMAR 

You need to use ExtractText processor and matching regex to extract only the integer value.

---------------------------------------------

Add new property in ExtractText processor 

val

 

 

(\d+)

 

 

 -

Then use ReplaceText processor with below configs:

Search Value

}
Replacement Value
,"y":"${val}"}
Character Set
UTF-8
Maximum Buffer Size
1 MB
Replacement Strategy
Literal Replace
Evaluation Mode
Entire text

-

By using Replacetext processor we are extracting the value and adding "y" key with the extracted value.

--------------------------------------------

Input data:

 

 

{"x":"avc123.abc.com"}

 

 

 Output:

 

 

{"x":"avc123.abc.com","y":"123"}

 

 

 

View solution in original post

avatar
Master Guru

@ANMAR 

 

Try with this regex in ExtractText processor.

(?:"x":.\w+?)(\d+)

This regex will extract only the digit in "x" key and adds that value for "y" key in ReplaceText processor.

View solution in original post

5 REPLIES 5

avatar
Master Guru

@ANMAR 

You need to use ExtractText processor and matching regex to extract only the integer value.

---------------------------------------------

Add new property in ExtractText processor 

val

 

 

(\d+)

 

 

 -

Then use ReplaceText processor with below configs:

Search Value

}
Replacement Value
,"y":"${val}"}
Character Set
UTF-8
Maximum Buffer Size
1 MB
Replacement Strategy
Literal Replace
Evaluation Mode
Entire text

-

By using Replacetext processor we are extracting the value and adding "y" key with the extracted value.

--------------------------------------------

Input data:

 

 

{"x":"avc123.abc.com"}

 

 

 Output:

 

 

{"x":"avc123.abc.com","y":"123"}

 

 

 

avatar
Explorer

@Shu_ashu  Thank you very much! You saved the day for me. 

avatar
Explorer

How about when i have multiple fields such as {
"x":"avc123.abc.com",
"z":"24 - ny"
}
and I would like to only targer "x" value for "123" and the rest won't get affected such as "z"
so the expected output would be {
"x":"avc123.abc.com",
"z":"24 - ny",
"y":"123"
}

Please note that the "y" value only targeted the "x" and the z shouldn't be picked up?
 

avatar
Explorer

@Shu_ashu  I will wait for your response my friend. Thanks! 

avatar
Master Guru

@ANMAR 

 

Try with this regex in ExtractText processor.

(?:"x":.\w+?)(\d+)

This regex will extract only the digit in "x" key and adds that value for "y" key in ReplaceText processor.