Skip to main content

Filtered Selectors

Source file: examples/filtered_selector_variables.hen

What It Demonstrates

  • filtered array selectors with $VARIABLE values
  • captures that reuse values captured earlier in the same request
  • assertions against the matched array item

Key Pattern

$ EXPECTED_EMAIL = Kira92@hotmail.com

GET https://lorem-api.com/api/users

? count = 2
? seed = 1234

& body.[? email == $EXPECTED_EMAIL].name -> $TARGET_NAME
& body.[? name == $TARGET_NAME].avatar -> $TARGET_AVATAR

^ & body.[? email == $EXPECTED_EMAIL].name == 'Carroll Hettinger'
^ & body.[? name == $TARGET_NAME].email == $EXPECTED_EMAIL

Run It

hen verify ./examples/filtered_selector_variables.hen
hen run ./examples/filtered_selector_variables.hen 0 --non-interactive

What To Notice

  • Each [? ...] selector must resolve to exactly one array element.
  • The second selector reuses a value captured earlier in the same request.
  • This pattern works well with seeded demo data because the expected match stays stable across runs.

Related reference: JSON selection