Skip to content

Filtering

PhantomJSON supports filtering resources by field values using query parameters.

Filter by exact match using the field name as a query parameter:

Terminal window
curl "https://api.phantomjson.app/v1/users?firstName=John"

Use bracket notation for comparison operators:

?field[operator]=value
Operator Description Example
(none) Equals (default) ?firstName=John
neq Not equals ?firstName[neq]=John
gt Greater than ?id[gt]=10
gte Greater than or equal ?price[gte]=50
lt Less than ?id[lt]=20
lte Less than or equal ?price[lte]=200
in In list ?id[in]=1,5,10
ct Contains ?firstName[ct]=oh
sw Starts with ?firstName[sw]=Jo
ew Ends with ?lastName[ew]=son
Terminal window
curl "https://api.phantomjson.app/v1/products?price[gte]=50&price[lte]=200"
Terminal window
curl "https://api.phantomjson.app/v1/users?firstName[ct]=oh"
Terminal window
curl "https://api.phantomjson.app/v1/todos?id[in]=1,5,10"
Terminal window
curl "https://api.phantomjson.app/v1/users?firstName[neq]=John"

Multiple filters are combined with AND logic:

Terminal window
curl "https://api.phantomjson.app/v1/products?category=smartphones&price[gte]=100"

Each resource has specific filterable fields:

Resource Filterable Fields
Users id, firstName, lastName, email
Posts id, userId, title
Comments id, postId, name, email
Todos id, userId, title, completed
Albums id, userId, title
Photos id, albumId, title
Products id, name, category

All string filters are case-insensitive:

Terminal window
# These are equivalent
curl "https://api.phantomjson.app/v1/users?firstName=john"
curl "https://api.phantomjson.app/v1/users?firstName=JOHN"