Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to reference a key/value pair from JSON of different structure

avatar
Contributor

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

1 ACCEPTED SOLUTION

avatar

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

View solution in original post

4 REPLIES 4

avatar

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

avatar
Contributor

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.

avatar

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"

avatar
Contributor

Thank you.