JSON:API is an open specification for building HTTP APIs that exchange JSON, defining exactly how clients request resources and how servers format responses, relationships and errors. Within the field of APIs in programming, it serves as a shared convention for resource-oriented interfaces, so teams stop debating payload shapes and reuse generic client and server libraries instead.
The JSON API specification reached version 1.0 in 2015, and version 1.1 added extensions and profiles while staying backward compatible. It uses its own media type, application/vnd.api+json, and focuses on reducing the number of requests and the size of payloads through compound documents and sparse fieldsets.
How a JSON:API document is structured
Every JSON:API response is a top-level document object that must contain at least one of data, errors or meta, and never data and errors together. Primary data is either a single resource object or an array of them, and each resource is identified by the pair of type and id.
A resource object separates its content into attributes and relationships. Attributes hold the resource’s own values, while relationships contain resource identifier objects that point to related resources by type and id, optionally with links to fetch them. This separation lets clients build a normalized local cache without custom parsing rules.
The table below lists the main members of a document and of a resource object.
| Member | Location | Purpose |
|---|---|---|
data | Top level | Primary resource or resource collection |
included | Top level | Related resources in a compound document |
errors | Top level | Array of error objects |
meta | Top level or resource | Non-standard metadata such as totals |
links | Top level or resource | Self, related and pagination URLs |
attributes | Resource object | The resource’s own field values |
relationships | Resource object | References to other resources |
Query parameters for fetching data
JSON:API reserves a small set of standard query parameters that give clients control over what a server returns. The include parameter requests a compound document, in which related resources are delivered in the included array, each exactly once, eliminating repeated round trips.
The specification defines the syntax of some parameters strictly and leaves the strategy of others to the server. Filtering and pagination, for instance, reserve parameter names but do not mandate a strategy, so a server may choose offset, page number or cursor-based pagination.
| Parameter | Example | Effect |
|---|---|---|
include | include=author,comments | Adds related resources to the response |
fields[type] | fields[articles]=title | Returns only the listed fields |
sort | sort=-created,title | Orders results; a minus sign means descending |
page[...] | page[size]=20 | Selects a page; strategy is server-defined |
filter[...] | filter[status]=published | Narrows results; semantics are server-defined |
Sparse fieldsets via fields matter for mobile clients, because a list screen may need only two attributes out of thirty. Combined with includes, they let one request deliver exactly the data a view requires.
Writing data, status codes and errors
JSON:API maps create, update and delete operations onto standard HTTP methods. A POST creates a resource and returns 201 Created, a PATCH updates only the supplied attributes or relationships, and a DELETE removes the resource. Relationships can also be modified directly through relationship endpoints.
Errors are returned as an array of error objects, each of which may carry a status, an application-specific code, a human-readable title and detail, and a source pointer that identifies the offending field with a JSON Pointer such as /data/attributes/email. This makes form validation errors straightforward to display.
Content negotiation is strict: a server must respond with 415 Unsupported Media Type if a request uses the JSON:API media type with unsupported parameters, and with 406 Not Acceptable under the corresponding conditions for the Accept header.
How JSON:API compares with other API styles
JSON:API is a convention layered on REST, not a different protocol. It competes mainly with ad hoc REST designs, GraphQL and OData, each of which answers the problem of flexible data fetching differently.
| Approach | Data selection | Main strength | Main drawback |
|---|---|---|---|
| JSON:API | include and fields parameters | Standard REST format, HTTP caching | Verbose envelopes |
| Ad hoc REST | Custom per endpoint | Complete freedom | Inconsistent conventions |
| GraphQL | Client-defined query language | Precise nested selection | Harder HTTP caching |
| OData | Rich URL query syntax | Powerful querying | Large, complex specification |
Unlike GraphQL, JSON:API keeps one URL per resource, so ordinary HTTP caches, CDNs and ETags work as expected. Unlike OData, it deliberately stays small and leaves query semantics such as filtering to the server, which simplifies adoption but limits interoperability between implementations.
Adoption decisions and common pitfalls
JSON:API fits best when an API exposes many related resources, when several client teams consume it, and when generic libraries are valued over hand-tuned payloads. Mature server and client libraries exist for most major languages and frameworks.
| Situation | Recommendation | Reason |
|---|---|---|
| Resource-centric CRUD API | Strong fit | Specification covers nearly all needs |
| Highly nested, client-driven views | Consider GraphQL | Deep selection is more natural there |
| Command-style operations | Weak fit | Actions do not map cleanly to resources |
| Public API with many consumers | Strong fit | Shared conventions reduce documentation |
- Unbounded includes can trigger expensive joins; servers should whitelist allowed include paths.
- Inventing custom filter syntax without documentation defeats the purpose of a shared standard.
- Wrong media type in requests or responses breaks strict clients and should be tested early.
- Exposing database IDs as resource ids couples clients to storage; ids must be strings in any case.
Explained without jargon
JSON:API is a shared rulebook for how apps and servers talk in JSON. Instead of every company inventing its own layout for data, everyone follows the same pattern for describing items, their connections and their errors.
It works like a standard shipping label: any carrier knows where to find the address and the weight. Because the layout is predictable, developers can reuse ready-made tools and ask for related data in a single trip rather than several.
A typical use case
A publishing company runs a content API used by a website, two mobile apps and a partner portal. The article list screen previously made one request for articles plus one per author, often 21 requests for a page of 20 items.
After moving to JSON:API, the mobile app calls /articles?include=author&fields[articles]=title,summary&fields[people]=name&page[size]=20. The server returns the 20 articles and each distinct author exactly once in the included array. The screen now needs a single request, the payload shrinks by roughly two thirds because unused attributes are omitted, and the partner team integrates with a generic open-source client instead of writing custom parsing code.