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
Only works with executor: http tests that return JSON responses. The response must have a valid JSON body.

Fields

FieldRequiredDescription
pathyesJSONPath expression starting with $
expectedyesExpected value, or exists to check field presence

JSONPath syntax

JSONPath expressions start with $ (the root) and navigate the JSON structure:

ExpressionMeaning
$.fieldTop-level field
$.nested.fieldNested field
$.array[0]First array element
$.array[*].namename 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"