Jteck
Jteck

Reputation: 11

Rest-Assured: Grabbing a JSON response inside an Array

Lets say I have a JSON response that returns an array:

[
   {
      "username": "dude",
      "id": 123456,
   },
   {
      "username": "hello",
      "id": 654321,
   }
]

How would I grab an element in the array using using Rest-Assured? For example I would just want to grab the first element of the array and print it.

Upvotes: 0

Views: 1582

Answers (1)

RocketRaccoon
RocketRaccoon

Reputation: 2609

Use following code

given()
    .when()
    .get()
    .then().extract().path() // or .extract().jsonpath()

Upvotes: 1

Related Questions