Field Selection
PhantomJSON supports selecting only the fields you need using the fields query parameter.
Syntax
Section titled “Syntax”?fields=field1,field2,field3Example
Section titled “Example”curl "https://api.phantomjson.app/v1/users?fields=id,firstName,email"Response
Section titled “Response”{ "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 }}Selectable Fields
Section titled “Selectable Fields”| 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 |
Examples
Section titled “Examples”Minimal User
Section titled “Minimal User”curl "https://api.phantomjson.app/v1/users?fields=id,firstName"Product Summary
Section titled “Product Summary”curl "https://api.phantomjson.app/v1/products?fields=id,name,price,category"Post with Author ID
Section titled “Post with Author ID”curl "https://api.phantomjson.app/v1/posts?fields=id,title,userId"Combining with Other Parameters
Section titled “Combining with Other Parameters”Field selection works with all other query parameters:
# Paginated, filtered, with field selectioncurl "https://api.phantomjson.app/v1/users?fields=id,firstName,email&sort=firstName:asc&limit=10"Default Behavior
Section titled “Default Behavior”If no fields parameter is provided, all fields are returned:
# These are equivalentcurl "https://api.phantomjson.app/v1/users"curl "https://api.phantomjson.app/v1/users?fields=id,firstName,lastName,email,createdAt,updatedAt"