Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NIFI JSON event extraction only integers from string

Solved Go to solution

NIFI JSON event extraction only integers from string

New Contributor

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

Accepted Solutions

Re: NIFI JSON event extraction only integers from string

Super 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"}

 

 

 

Highlighted

Re: NIFI JSON event extraction only integers from string

Super 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.

5 REPLIES 5

Re: NIFI JSON event extraction only integers from string

Super 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"}

 

 

 

Re: NIFI JSON event extraction only integers from string

New Contributor

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

Re: NIFI JSON event extraction only integers from string

New Contributor

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?
 

Re: NIFI JSON event extraction only integers from string

New Contributor

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

Highlighted

Re: NIFI JSON event extraction only integers from string

Super 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.