jsonPath
Check values inside a JSON response body using JSONPath expressions. This is the most powerful assertion for HTTP API tests — you can verify any field in any JSON structure.
assertions:
- jsonPath:
path: $.token
expected: exists
assertions:
- jsonPath:
path: $.user.email
expected: "test@example.com"
assertions:
- jsonPath:
path: $.data[0].id
expected: 1
Only works with
executor: http tests that return JSON responses. The response must have a valid JSON body.Fields
| Field | Required | Description |
|---|---|---|
path | yes | JSONPath expression starting with $ |
expected | yes | Expected value, or exists to check field presence |
JSONPath syntax
JSONPath expressions start with $ (the root) and navigate the JSON structure:
| Expression | Meaning |
|---|---|
$.field | Top-level field |
$.nested.field | Nested field |
$.array[0] | First array element |
$.array[*].name | name field from every array element |
$.data[-1] | Last array element |
Examples
Check a field exists
Useful when you don't care about the exact value — just that it's present in the response.
assertions:
- jsonPath:
path: $.token
expected: exists
Check exact value
assertions:
- jsonPath:
path: $.status
expected: "success"
Check numeric value
assertions:
- jsonPath:
path: $.count
expected: 42
Check boolean
assertions:
- jsonPath:
path: $.active
expected: true
Check nested object
assertions:
- jsonPath:
path: $.user.role
expected: "admin"
Check array element
assertions:
- jsonPath:
path: $.items[0].name
expected: "First item"
Combining with other assertions
You can use multiple jsonPath assertions alongside statusCode to verify both the response code and body:
assertions:
- statusCode:
equals: 200
- jsonPath:
path: $.token
expected: exists
- jsonPath:
path: $.user.email
expected: "test@example.com"