JSONPath is a query language for selecting values within JSON responses. In API acceptance tests, it extracts only the data a scenario needs, reducing dependence on incidental response fields. section 13.0 section 13.4.2
Use JSONPath to retrieve:
- Top-level values by name, with typed access such as getString() and getInt(). section 13.4.3
- Nested values through dot notation, such as passport.number. section 13.4.3
- Nested structures as Java domain objects with getObject(). section 13.4.3
- Collections of matching values or objects with getList(). section 13.4.3
Extracting a registration number
After registering a frequent-flyer member through a REST API, retrieve only the returned identifier: response.jsonPath().getString("frequentFlyerNumber"). The test can then use that value without depending on the complete JSON structure. section 13.4.2
Listing 13.1 A sample JSON response
{
"frequentFlyerNumber": 1000036,
"firstName": "Tracy",
"lastName": "Traveler",
"email": "tracy@example.org",
"flightHistory": [
{
"from": "London",
"to": " Paris",
"date": "2021-12-15"
},
{
"from": "Paris",
"to": " London",
"date": "2021-12-21"
}
],
"passport": {
"number": "12345678",
"country": "United Kingdom"
}
}
A sample response provides the nested passport object and flight-history array used by the JSONPath examples. section 13.4.3


