This step asserts that a specific property in the JSON response has an exact value. The property path is given as a dot-separated string, so nested objects can be reached with notation like user.role or meta.total. The expected value is parsed from the step text: bare numbers become JavaScript numbers, true and false become booleans, and a value wrapped in double quotes is treated as a string. A strict equality check is performed, so type matters - 1 is not the same as "1".
Placeholder tokens such as {{userId}} that were set earlier in the scenario are substituted in the expected value before the comparison runs. The step uses three syntactic variants - the JSON response should have, the API response should have, and the JSON property - all backed by the same assertion.
Accepted phrasings
Then the JSON response should have "property" equal to value
Then the JSON response should have "property" equal to "string value"
Then the API response should have "property" equal to value
Then the JSON property "property" should be value
Then the JSON property "property" should be "string value"
Examples
Then the JSON response should have "name" equal to "Jane Smith"
Then the API response should have "id" equal to 1
Then the JSON property "active" should be true
Then the JSON response should have "user.role" equal to "admin"
In a real scenario
Scenario: Fetching a user record returns correct field values
Given the API base URL is "https://api.example.org/v1"
And I set header "Accept" with value "application/json"
When I send a GET request to "/users/42"
Then the API response code should be 200
And the response should be valid JSON
And the JSON response should have "id" equal to 42
And the JSON response should have "email" equal to "alice@example.org"
And the JSON property "active" should be true
And the JSON response should have "profile.role" equal to "editor"