PKR
PKR

Reputation: 187

How to get the required content from a JSON string

I have a variable in Robot Frame Work having Json response body in the following format

{
   "jsonrpc": "2.0",
   "id": "787878",
   "result":
   {
       "content":
       [
           {
               "id": 30,
               "userID": "user",
               "eventType":
               {
                   "name": "test"
               },
               "timestamp": "2013-03-13T11:00:28.537Z",
               "source": "Service",
               "reason": null,
               "comment": null,
               "dataCache":
               {
                   "lastLogin":
                   {
                       "id": 103,
                       "fieldName": "value1",
                       "newValue": "Wed Mar 13 07:00:28 EDT 2013",
                       "oldValue": null,
                       "type": "java.util.Date",
                       "auditEvent": null
                   }
               },
               "authority": "authenticate",
               "auditedObject": null
           }
       ],
       "pageNumber": 0,
       "pageSize": 99,
       "numberOfElements": 1,
       "totalElements": 1,
       "lastPage": true,
       "totalPages": 1
   }

}

SO from this How can I get the content of only datacache as shown in the below

{
   "lastLogin":
   {
       "id": 103,
       "fieldName": "value1",
       "newValue": "Wed Mar 13 07:00:28 EDT 2013",
       "oldValue": null,
       "type": "java.util.Date",
       "auditEvent": null
   }
},

If I use a variable like ${variable['result']['content']} , I will get entire body in the content But I just want a body in "DataCache":

Please help me to solve this issue..

Upvotes: 2

Views: 2773

Answers (2)

Rajesh Chaudhary
Rajesh Chaudhary

Reputation: 112

${variable['result']['content'][0]['dataCache']}

worked in my case.

Upvotes: -1

Scorpil
Scorpil

Reputation: 1526

${variable['result']['content'][0]['dataCache']}

Is this what you're looking for? Maybe you need some more practice with JSON then...

Upvotes: 5

Related Questions