- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
NIFI extract text from JSON
- Labels:
-
Apache NiFi
Created ‎02-17-2018 07:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using the NIFI ExtractText Processor and I'm trying to come up with the regular expression to extract a field value from a JSON String. Sample JSON Data is:
{"ID": 10649, "ORDER_ID": 85, "PRODUCT_ID": "JT8382X38", "CUSTOMER_ID": 57, "QUANTITY": 2, "ORDER_DATE": "2018-02-17 11:09:56.217", "REGION": "Far East", "NOTES": "Repeat Purchase", "AMOUNT": "7997.48", "STATUS": 105}
I want to extract the ID field value (10649). What would be a valid regular expression to get this value?
Thanks!
Created on ‎02-17-2018 07:50 PM - edited ‎08-17-2019 07:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In Extract Text processor add new property as
ID
Regex:-
"ID":(.*?),
(or)
As you are having json message instead of Extract text processor use Evaluatejson processor and change below properties
Destination
flowfile attribute
add new property as
ID
$.ID
will add new attribute called ID as flowfile attribute.
Configs:-
Created ‎02-18-2018 11:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To match white space use the below regex
ID
"ID":\s(.*?),
\s matches any whitespace character (equal to [\r\n\t\f\v ]).
You can validate your regex here regex
We need to match whitespaces if we are using extract text processor,don't need to match any whitespace characters if you are using Evaluatejson path processor to extract content and keep it as attribute to the flowfile.
Created ‎02-18-2018 11:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much, both of those solutions worked.
Question:
When using the ExtractText processor, how can I account for whitespace between the colon : and the actual ID string?
This does not seem to work:
"ID":(\w+)(.*?),
If the start of my string is:
{"ID": 12345,
and I want to get the value 12345
Thanks!
