getting length of values in array returned in json object

4,240 views
Skip to first unread message

markg

unread,
Mar 26, 2013, 6:01:05 PM3/26/13
to rest-a...@googlegroups.com
Using restassured and doing a get on an endpoint, I'm getting back this json object in the response and am trying to find a way to determine the number of values associated with "Names" .

{

    "Names": ["HOTP","AuthConfiguration","Federation","Repository","Policy","Service","LDAP","DataStore","SAE","Delegation","Module","OATH"]

}

Any help appreciated.

Johan Haleby

unread,
Mar 27, 2013, 3:40:02 AM3/27/13
to rest-a...@googlegroups.com
Hi, 

Do you want to validate the length or extract the length from the document? If you want to validate you can do:

expect().
             body("Names.size()", is(12)).
when().
           get("/endpoint");

if you want to extract the size you can do:

int size = get("/endpoint").path("Names.size()");


Regards,
/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

markg

unread,
Mar 27, 2013, 2:41:46 PM3/27/13
to rest-a...@googlegroups.com
Johan,

I was looking to extract the length.  But, after some further research found that this wasn't necessary.  I was really just wanted to extract the values from the array.  This code
response.getBody().jsonPath().getList("serviceNames", String.class);

gets the values as a list and allows me to iterate over it.

Nelson Gutiérrez

unread,
May 17, 2016, 1:19:13 PM5/17/16
to REST assured
Hello Markg, 

Can you please provide more information of how would you be able of make it work, like an example with the complete structure. Thank you
Reply all
Reply to author
Forward
0 new messages