Search code examples
jsonrest-assuredrest-assured-jsonpath

Parsing JSONArray when no key is present using restassured


i am using restassured to test my rest APIs and I have a scenario where my rest API returns a JSONArray without any key value like below. While browsing through multiple questions i havent seen similar JSONArray handled without key value. Verifying such a JSON is supported by RestAssured ?

[ "Test_1 Bundle_01", "Test_2 Bundle_02", "Test_3 Bundle_03" ]


Solution

  • Found a way to do this by using jsonpath.

    List<String> newlist = JsonPath.with(response.asInputStream()).get("$");
    System.out.println(newlist.get(0).toString());
    

    By using jsonpath and storing the response in a list of string, individual string can be accessed easily.