find Method — Complete Examples
find is a declarative replacement for a for loop over a JSON array. It iterates the elements of a JSON array, matches a predicate against each element (referenced with the bare alias item), optionally projects a field, and stores the result — with its proper type — into a variable.
Syntax reminder
- Inside
where/select, writeitembare (item.company.name) —findreads the field directly and auto‑quotes strings for you. Only quote the literal you compare against. sourcekeeps the$prefix (source=$users.Body).- Reference external variables in
wherewith the normal placeholder form (${threshold}).
All examples below capture the public jsonplaceholder users array first, then use find.
Find one and reuse it in the URL
Find the id of the user whose username is Bret, store it in userId, and use it in the next request.
name: FindDemo
rounds:
- name: FindRound
numberOfClients: 1
arrivalDelay: 1000
runInParallel: false
iterations:
- name: getUsers
httpRequest:
capture:
to: users
as: Json
makeGlobal: true
url: https://jsonplaceholder.typicode.com/users
method: GET
- name: getUserAlbums
before:
- '$find(source=$users.Body, where=item.username == "Bret", select=item.id, match=first, variable=userId)'
httpRequest:
url: 'https://jsonplaceholder.typicode.com/users/${userId}/albums'
method: GET
match = all (collect every matching value)
Collect the ids of every user whose id is greater than 5 into a JSON array.
name: FindAllDemo
rounds:
- name: FindRound
numberOfClients: 1
arrivalDelay: 1000
runInParallel: false
iterations:
- name: getUsers
httpRequest:
capture:
to: users
as: Json
makeGlobal: true
url: https://jsonplaceholder.typicode.com/users
method: GET
- name: collectBigIds
before:
- '$find(source=$users.Body, where=item.id > 5, select=item.id, match=all, variable=bigIds)'
httpRequest:
headers:
X-Big-Ids: '${bigIds}'
url: https://jsonplaceholder.typicode.com/posts/1
method: GET
bigIds is stored as the JSON array [6,7,8,9,10].
match = count
Count how many users live in the city Gwenborough (stored as an integer).
name: FindCountDemo
rounds:
- name: FindRound
numberOfClients: 1
arrivalDelay: 1000
runInParallel: false
iterations:
- name: getUsers
httpRequest:
capture:
to: users
as: Json
makeGlobal: true
url: https://jsonplaceholder.typicode.com/users
method: GET
- name: countCity
before:
- '$find(source=$users.Body, where=item.address.city == "Gwenborough", match=count, variable=cityCount)'
httpRequest:
headers:
X-City-Count: '${cityCount}'
url: https://jsonplaceholder.typicode.com/posts/2
method: GET
Store the whole (navigable) object, then verify with skipIf
With no select, find stores the entire matched element as navigable JSON, so you can read its fields later (${matchedUser.id}, ${matchedUser.username}).
name: FindObjectDemo
rounds:
- name: FindRound
numberOfClients: 1
arrivalDelay: 1000
runInParallel: false
iterations:
- name: getUsers
httpRequest:
capture:
to: users
as: Json
makeGlobal: true
url: https://jsonplaceholder.typicode.com/users
method: GET
- name: useMatchedUser
before:
- '$find(source=$users.Body, where=item.company.name == "Romaguera-Crona", match=first, variable=matchedUser)'
# skipIf skips when TRUE, so this runs only when the match is who we expect.
skipIf: '"${matchedUser.username}" != "Bret" or ${matchedUser.id} != 1'
httpRequest:
url: 'https://jsonplaceholder.typicode.com/users/${matchedUser.id}/todos'
method: GET
Multiple expressions and an external variable
Run several finds in order, and compare an item field against an external variable.
name: FindMultiDemo
variables:
- name: threshold
as: string
value: "5"
rounds:
- name: FindRound
numberOfClients: 1
arrivalDelay: 1000
runInParallel: false
iterations:
- name: getUsers
httpRequest:
capture:
to: users
as: Json
makeGlobal: true
url: https://jsonplaceholder.typicode.com/users
method: GET
- name: doWork
before:
- '$find(source=$users.Body, where=item.username == "Bret", select=item.id, match=first, variable=userId)'
- '$find(source=$users.Body, where=item.id > ${threshold}, select=item.id, match=all, variable=bigIds)'
httpRequest:
headers:
X-Big-Ids: '${bigIds}'
url: 'https://jsonplaceholder.typicode.com/users/${userId}/albums'
method: GET