Skip to content

Sorting

PhantomJSON supports sorting by one or more fields.

Terminal window
?sort=field:direction
Parameter Values Default
field Any sortable field id
direction asc or desc asc
Terminal window
curl "https://api.phantomjson.app/v1/users?sort=firstName:asc"

Separate multiple sort fields with commas:

Terminal window
curl "https://api.phantomjson.app/v1/users?sort=lastName:asc,firstName:desc"
Resource Sortable Fields
Users id, firstName, lastName, email
Posts id, userId, title
Comments id, postId, name
Todos id, userId, title
Albums id, userId, title
Photos id, albumId, title
Products id, name, price
Terminal window
curl "https://api.phantomjson.app/v1/users?sort=firstName:asc"
Terminal window
curl "https://api.phantomjson.app/v1/posts?sort=createdAt:desc"
Terminal window
curl "https://api.phantomjson.app/v1/products?sort=price:asc"
Terminal window
# Sort by last name, then first name
curl "https://api.phantomjson.app/v1/users?sort=lastName:asc,firstName:asc"

Sorting works with pagination, filtering, and search:

Terminal window
# Sorted, paginated results
curl "https://api.phantomjson.app/v1/users?sort=firstName:asc&page=1&limit=10"
# Sorted, filtered results
curl "https://api.phantomjson.app/v1/products?category=smartphones&sort=price:desc"