🗂️ JSON Path & Schema Validation
JSON Path & Schema Validation: JSON Path is like a warehouse map to deeply stored items: instead of saying "find the red box in the 5th container on the 2nd shelf of aisle 3," yo
JSON Path is like a warehouse map to deeply stored items: instead of saying "find the red box in the 5th container on the 2nd shelf of aisle 3," you write `data.items[2].colors[4]` — the warehouse worker follows the coordinates without opening every box along the way. You might say you can get the response body with `response.getBody().asString()` and reach the value you want using split or regex — so why learn JSON Path? Because code like `String.split(",")[3]` starts pulling the wrong value the moment an API changes a field ordering, and the test issues a false PASS. JSON Path navigates by field name, independent of order. In Java, when parsing with `JSONObject` manually you chain `getJSONObject("data").getJSONArray("users").getJSONObject(0).getString("email")` for every nested object; JSON Path reduces that to a single `"data.users[0].email"` string. The critical QA scenario: you want to take the `token` value from a login response and put it in the next test's bearer header — `String token = response.jsonPath().getString("token")` does it in one line, no SessionToken class needed, and each step in a chained test scenario cleanly carries the previous output via JSON Path.
extract() — Pulling Values from a Response
Micro Lab: REST Assured assertion writing
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
What Is the Difference Between extract().path() and extract().response()?
.extract().path("data.email") PULLS a…
`.extract().path("data.email")` PULLS a SINGLE field directly into a `String` — the SHORTEST path when you need nothing else.
The SAME JSON Path syntax WORKS for…
The SAME JSON Path syntax WORKS for both a single `String` (`data.email`) and a `List ` (`data.email` — applied across array elements) — REST Assured infers the type AUTOMATICALLY.
.extract().response() returns the…
`.extract().response()` returns the ENTIRE `Response` object — when you need multiple fields via `res.path(...)`, you extract ONCE and read REPEATEDLY instead of sending the request AGAIN.
res.asString() serves a COMPLETELY…
`res.asString()` serves a COMPLETELY different purpose: debug logging or CATCHING an unexpected format (like an HTML error page).
Advanced JSON Path — Groovy Filters