- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to reference a key/value pair from JSON of different structure
- Labels:
-
Apache NiFi
Created 05-10-2022 05:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please, is there a way to reference a key part of JSON file that can come in different structures.
For example i want to get the value of "requestUid" from these different JSON structures just with a single processor. So, irrespective of JSON formats or structures sent, i would want to get the value of requestUid.
Thanks.
For example:
1)
{
"responseMetaData": {
"type": "ACK",
"userId": "SYSTEM",
"requestUid": "1742963e-f02f-4db6-88e0-6af8c4d4825b",,
"systemId": "CIF",
"serviceId": "FR_CUS"
},
"responseDataObject": {
"result": "Accepted",
"responseCode": "SUC",
"responseMessage": "",
"execTime": "1216"
}
}
2)
{
"responseMetaData": {
"type": "ACK",
"sendTime": "23/03/2019 09:16:25.305277",
"timeZone": "4",
"userId": "SYSTEM",
"branchCompanyId": "784100",
"branchLocationId": "784101",
"systemId": "CIF",
"serviceId": "FR_CUS"
},
"responseDataObject": {
"result": "Accepted",
"responseCode": "SUC",
"requestUid": "yywhhnan56289200200",
"execTime": "1216"
}
}
Created 05-10-2022 12:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not sure if this is the the most efficient way, but you can use ExtractText by creating new attribute with the following regular expression:
(?<=\"requestUid\":\s")[A-Z-a-z-0-9\-]+
Not sure if you can accomplish that using evaluatejsonPath processor, but given that the path can be different its probably hard to accomplish
Created 05-10-2022 12:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not sure if this is the the most efficient way, but you can use ExtractText by creating new attribute with the following regular expression:
(?<=\"requestUid\":\s")[A-Z-a-z-0-9\-]+
Not sure if you can accomplish that using evaluatejsonPath processor, but given that the path can be different its probably hard to accomplish
Created 05-10-2022 01:00 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi SAMSAL,
Thank you so much. I got it working using your method at the moment.
Please, can you explain this RE to me or point me to a suitable material where i can learn this particular Regular Expression.
I really appreciate.
Created 05-10-2022 01:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a lot of articles\videos around learning Regular Expression. The one I provided using what is called positive lookbehind (?<=), which means: find the Id which contain alphanumeric characters with hyphen (-) that is proceeded (lookbehind) with the text "requestUid"
Created 05-10-2022 01:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
