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]
Created on
09-08-2019
02:23 PM
- last edited on
09-08-2019
11:13 PM
by
ask_bill_brooks
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.
Created on 09-08-2019 08:14 PM - edited 09-08-2019 08:15 PM
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
}
,"y":"${val}"}UTF-8
1 MB
Literal Replace
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"}
Created 09-09-2019 07:54 PM
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.
Created on 09-08-2019 08:14 PM - edited 09-08-2019 08:15 PM
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
}
,"y":"${val}"}UTF-8
1 MB
Literal Replace
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"}
Created 09-09-2019 05:51 AM
@Shu_ashu Thank you very much! You saved the day for me.
Created 09-09-2019 06:27 AM
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?
Created 09-09-2019 08:15 AM
@Shu_ashu I will wait for your response my friend. Thanks!
Created 09-09-2019 07:54 PM
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.