How to capture JSON item using selenium API

28 views
Skip to first unread message

azeddin...@hotmail.co.uk

unread,
May 25, 2018, 8:55:26 AM5/25/18
to Selenium Users
Hi , 
Can someone assist?.  I need to capture an item within JSON response displayed in eclipse/selenium console. The JOSN file looks as follows:
 
{
   "ID" : "28821b78-e7cda408-35e37-91ee8a7b-a34464df",
   "IsStable" : true,
   "LastUpdate" : "2017",
   "MainDicomTags" : {
      "PatientBirthDate" : "19331111",
      "PatientID" : "0092124",
      "PatientName" : "Oneby^^",
      "PatientSex" : "O"
   },
   "Studies" : [ "9cc51d8b-93b25cf5-6a1ab08d" ],
   "Type" : "Patient"
}
The item I want to capture is: PatientID 
My intended code is below but not getting the desired item: PatientID.
RestAssured.baseURI = "http://XXXXXX";
  RequestSpecification httpRequest = RestAssured.given();
   Response response = httpRequest.get("/2c1e37-91ee8a7b-a34464df");
       JsonPath json = response.jsonPath();
            String responseBody = response.getBody().asString();
//put into Array
               JSONArray MainDicomTags= (JSONArray)json.get("MainDicomTags");
                     for(int i=0; i<MainDicomTags.size(); i++){
      
                        System.out.println("The " + i + " element of the array: "+MainDicomTags.get(i));
       
                    } 
Thanks, 
AM.
                    
           
       

Yogesh Khachane

unread,
May 25, 2018, 9:34:40 AM5/25/18
to seleniu...@googlegroups.com

You can use for this scenario regular expression it will return u exact json objects whatever u want.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/13a69327-9ad3-4f54-9b45-fdc320969f68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

azeddin...@hotmail.co.uk

unread,
May 27, 2018, 9:15:32 AM5/27/18
to Selenium Users
Hi Yogesh - can you please elaborate more on to your answer?. 
Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages