Skip to main content
ANMAR
Silver ⭐️⭐️⭐️
Sep 8, 2019 9:23 PM UTC
Solved

NIFI JSON event extraction only integers from string

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.

Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
Sep 9, 2019 3:14 AM UTC

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

 

 

 

5 replies

Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
Sep 9, 2019 3:14 AM UTC

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

 

 

 

Translate
ANMAR
ANMARAuthor
Silver ⭐️⭐️⭐️
Sep 9, 2019 12:51 PM UTC

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

Translate