Skip to content

Field Selection

PhantomJSON supports selecting only the fields you need using the fields query parameter.

Terminal window
?fields=field1,field2,field3
Terminal window
curl "https://api.phantomjson.app/v1/users?fields=id,firstName,email"
{
"data": [
{ "id": 1, "firstName": "John", "email": "john@example.com" },
{ "id": 2, "firstName": "Jane", "email": "jane@example.com" }
],
"meta": {
"total": 100,
"page": 1,
"limit": 20,
"totalPages": 5
}
}
Resource Selectable Fields
Users id, firstName, lastName, email
Posts id, userId, title, body
Comments id, postId, name, email, body
Todos id, userId, title, completed
Albums id, userId, title
Photos id, albumId, title, url, thumbnailUrl
Products id, name, description, price, category
Terminal window
curl "https://api.phantomjson.app/v1/users?fields=id,firstName"
Terminal window
curl "https://api.phantomjson.app/v1/products?fields=id,name,price,category"
Terminal window
curl "https://api.phantomjson.app/v1/posts?fields=id,title,userId"

Field selection works with all other query parameters:

Terminal window
# Paginated, filtered, with field selection
curl "https://api.phantomjson.app/v1/users?fields=id,firstName,email&sort=firstName:asc&limit=10"

If no fields parameter is provided, all fields are returned:

Terminal window
# These are equivalent
curl "https://api.phantomjson.app/v1/users"
curl "https://api.phantomjson.app/v1/users?fields=id,firstName,lastName,email,createdAt,updatedAt"