TestProject Forum
Powered by leading experts in the test automation community

How to verify API response which is JSONArray object

Hello folks,

I’m trying to retrieve emails from inbucket using “RESTful API Client Addon”, however the response that is returned is in the form of JSONArray object. Do we have anything that will help me retrieve any particular value at any particular index in the array? JSONPath does not seem to be working in this case. Any clues please?


Hi @amit.paunikar . Thanks for reaching out.

You can find all the documentation about how to use JsonPath here:

JsonPath Result
$.store.book[ * ].author The authors of all books
$…author All authors
$.store.* All things, both books and bicycles
$.store…price The price of everything
$…book[2] The third book
$…book[-2] The second to last book
$…book[0,1] The first two books
$…book[:2] All books from index 0 (inclusive) until index 2 (exclusive)
$…book[1:2] All books from index 1 (inclusive) until index 2 (exclusive)
$…book[-2:] Last two books
$…book[2:] Book number two from tail
$…book[?(@.isbn)] All books with an ISBN number
$.store.book[?(@.price < 10)] All books in store cheaper than 10
..book[?(@.price <= [‘expensive’])] All books in store that are not “expensive”
$…book[?(@.author =~ /.*REES/i)] All books matching regex (ignore case)
$…* Give me every thing
$…book.length() The number of books

Kindly let me know if this was helpful.
You can also provide an example of your response so i will show you the exact way

Hi Vladyslav, thanks for your reply!

Here’s what my response from HTTP GET request looks like-
Server responded with the expected status code: 200.
The value of “$” is “[{“mailbox”:“in14”,“id”:“20200509T133757-0042”,“from”:“support.admin@drtst.in”,“to”:[“in14@d.in”],“subject”:“Welcome to Druva Cloud Platform”,“date”:“2020-05-09T13:37:57.539581421Z”,“size”:15589}]”.
Server returned response body:
[{“mailbox”:“in14”,“id”:“20200509T133757-0042”,“from”:"\u003csupport.admin@drtst.in\u003e",“to”:["\u003cin14@d.in\u003e"],“subject”:“Welcome to Druva Cloud Platform”,“date”:“2020-05-09T13:37:57.539581421Z”,“size”:15589}]

I want to extract some field from this response, say “id”. Since this is an array and not a proper json, I’m unable to do so.


When I try to use $.id, I get the following error-

Unable to get the value ’.id' due to an error: Expected to find an object with property ['id'] in path but found ‘net.minidev.json.JSONArray’. This is not a json object according to the JsonProvider: ‘com.jayway.jsonpath.spi.json.JsonSmartJsonProvider’.".
Server returned response body:
[{“mailbox”:“in15”,“id”:“20200516T164653-0044”,“from”:"\u003csupport.admin@drtst.in\u003e",“to”:["\u003cin15@d.in\u003e"],“subject”:“Welcome to Druva Cloud Platform”,“date”:“2020-05-16T16:46:53.690630569Z”,“size”:15589}]

1 Like