Then the JSON response should have property "propertyPath"

This step asserts that a named property exists in the JSON response, without checking its value. Property paths use dot notation, so user.email reaches a nested key inside a user object. The check only passes when the property is present and its value is not undefined - a property explicitly set to null or false is still considered to exist and will pass.

Use this step when you want to confirm that a field is included in a response without caring about its exact content - for example, verifying that a created resource has an id or that a paginated list includes a meta block. To also verify the value, use the property equal to step instead.

Accepted phrasings

Then the JSON response should have property "name"
Then the API response should contain property "name"
Then the JSON response should have property "parent.child"
Then the API response should contain property "parent.child"

Examples

Then the JSON response should have property "id"
Then the API response should contain property "user.email"
Then the JSON response should have property "createdAt"
Then the API response should contain property "meta.total"

In a real scenario

Scenario: A newly created resource includes required fields
  Given the API base URL is "https://api.example.org/v1"
  And I set header "Content-Type" with value "application/json"
  When I send a POST request to "/articles" with body:
    """
    {
      "title": "Welcome",
      "body": "First post"
    }
    """
  Then the API response code should be 201
  And the response should be valid JSON
  And the JSON response should have property "id"
  And the JSON response should have property "createdAt"
  And the API response should contain property "author.name"

Related steps

Back to Api Steps