To extract values from a JSON response, use the
JsonPath
class, which allows you to parse and query JSON data.
Example :
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.path.json.JsonPath;
public class ExtractValues {
public static void main(String[] args) {
Response response = RestAssured.get("https://api.example.com/data");
JsonPath jsonPath = response.jsonPath();
String value = jsonPath.getString("key");
System.out.println("Extracted Value: " + value);
}
}?
In this example, the
jsonPath
method is used to create a
JsonPath
object, which allows you to extract values using JSON path expressions.