xPath of JSON response in soapUI

2.7k views Asked by At

can anyone help in finding xpath of 'tenantId' which is in JSON response given below

{
   "statusCode": "200",
   "errorParams": null,
   "payLoad":    {
      "UGX:XCD":       {
         "id": 42802,
         "fromCurrency":          {
            "tenantId": "2a610af6-2e42-4a78-8e04-98755e2c6113",
            "code": "UGX",
            "name": "Ugandan Shilling",
            "isoCode": "UGX",
            "active": true,
            "enabled": true,
            "flagModifiedName": false,
            "erpId": null,
            "createdOn": 1427155200000,
            "fieldLibraryStatus": "DRAFT",
            "userId": null
         },
         "toCurrency":          {
            "tenantId": "2a610af6-2e42-4a78-8e04-98755e2c6113",
            "code": "XCD",
            "name": "East Caribbean Dollar",
            "isoCode": "XCD",
            "active": true,
            "enabled": true,
            "flagModifiedName": true,
            "erpId": null,
            "createdOn": 1427155200000,
            "fieldLibraryStatus": "DRAFT",
            "userId": "c7f68b05-044d-44e1-8fc5-0f97a4ece91b"
         },
         "rate": 33,
         "inverseRate": 0.0303,
         "createdOn": 1434025926983,
         "modifiedOn": 1434326400000,
         "active": true,
         "purpose": "cmd",
         "enabled": true,
         "tenantFlag": true,
         "erpId": null
      }

How to traverse till 'tenantId' ??

Thanks in Advance.

2

There are 2 answers

0
SiKing On BEST ANSWER

SoapUI internally converts almost anything to XML. You will have to use the ResponseAsXml property. In the GUI, if you click on the XML tab, you can see this representation.

Something like the following should work:

${test_step#ResponseAsXml#//*:fromCurrency/*:tenantId}
${test_step#ResponseAsXml#//*:toCurrency/*:tenantId}
1
Karthic.K On

If you want to handle this using groovy, then extend SOAPUI with GSON.jar library provided by Google. this library specially written to handle the JSON objects.

With this you can rip every individual objects and its attribute-values easily how complex may the JSON object be, a nice add-on to work with.