JSON:API Specification: Format Guide & Implementation
JSON:API is a battle-tested specification for structuring JSON responses from REST APIs. It standardizes resource objects, relationships, links, filtering, sorting, and pagination so that clients and servers speak the same language without custom conventions.
Core Resource Object Structure
Every JSON:API response wraps resources in a top-level data key. Each resource has a type, id, attributes, and optionally relationships and links:
// GET /articles/1
// Content-Type: application/vnd.api+json
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API Explained",
"body": "JSON:API standardizes your REST responses...",
"published-at": "2026-01-15T10:00:00Z"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
},
"tags": {
"data": [
{ "type": "tags", "id": "2" },
{ "type": "tags", "id": "7" }
]
}
},
"links": {
"self": "/articles/1"
}
}
} Sideloading Related Resources (included)
Avoid N+1 requests by including related resources in the same response using the included array. Clients request this with the include query parameter:
// GET /articles/1?include=author,tags
{
"data": {
"type": "articles",
"id": "1",
"attributes": { "title": "JSON:API Explained" },
"relationships": {
"author": { "data": { "type": "people", "id": "9" } }
}
},
"included": [
{
"type": "people",
"id": "9",
"attributes": { "name": "Vic Chen", "twitter": "@vicdev" }
},
{
"type": "tags",
"id": "2",
"attributes": { "name": "api-design" }
}
]
} Filtering, Sorting & Sparse Fieldsets
JSON:API recommends standard query parameter patterns for common operations. Implementations define the exact filter syntax, but the parameter names are standardized:
# Filter articles by status
GET /articles?filter[status]=published
# Sort ascending by title, descending by published date
GET /articles?sort=title,-published-at
# Sparse fieldsets: only return title and body attributes
GET /articles?fields[articles]=title,body
# Combine: paginate + filter + include author
GET /articles?page[number]=2&page[size]=10&filter[status]=published&include=author
# Response includes pagination links
# {
# "data": [...],
# "links": {
# "first": "/articles?page[number]=1&page[size]=10",
# "prev": "/articles?page[number]=1&page[size]=10",
# "next": "/articles?page[number]=3&page[size]=10",
# "last": "/articles?page[number]=12&page[size]=10"
# }
# } JSON:API vs REST vs GraphQL
| Feature | JSON:API | Plain REST | GraphQL |
|---|---|---|---|
| Response shape | Standardized | Custom per API | Query-defined |
| Relationships | Built-in + sideloading | Manual nesting | Native graph |
| Over-fetching | Sparse fieldsets | Common problem | Eliminated |
| Learning curve | Medium | Low | High |
| Caching (HTTP) | Full HTTP cache | Full HTTP cache | POST-based, harder |
| Client libraries | ember-data, jsonapi-js | Any HTTP client | Apollo, urql |
Related Products
on GumroadDevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Interview Vault
210 technical interview questions with model answers, key points, and follow-up questions. Covers Frontend, Backend, System Design, and DSA — bilingual English + Traditional Chinese (ZH-TW). PWYW from $29.
Buy on Gumroad →You Might Also Need
JSON Diff Viewer
Free JSON diff viewer. Compare two JSON objects side-by-side with color-coded highlights: added lines in green, removed in red. Auto-formats JSON before comparing. Runs in your browser — your data nev
Open free tool →
JSON Diff
Free JSON diff tool. Compare two JSON objects side-by-side with color-coded highlights: added lines in green, removed in red. Auto-formats JSON before comparing. Runs in your browser — your data never
Open free tool →
JSON Formatter Pro
Free JSON Formatter Pro. Format, validate, and beautify JSON online. Query your JSON with JSONPath expressions to extract nested values instantly. Runs 100% in your browser — no data sent to any serve
Open free tool →
More Free Tools
Related Articles
Complete HTTP Status Codes Reference for REST API Devs
The complete HTTP status codes reference for REST API developers. Every 1xx, 2xx, 3xx, 4xx, and 5xx code explained with real-world API examples and best practices.
REST API Best Practices: Endpoint Naming, Versioning, and Error Handling
Design clean, consistent REST APIs with proper URL naming, HTTP methods, versioning, error formats, pagination, auth, and rate limiting.
Understanding REST API Design Best Practices
A practical guide to designing REST APIs that developers love — covering resource modeling, HTTP semantics, status codes, versioning, and error handling.
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
FastAPI vs Django REST Framework 2025: Which Should You Choose?
FastAPI vs Django REST Framework compared for 2025. Performance benchmarks, feature comparison, real-world use cases, and a clear decision guide for your next Python API project.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →Frequently Asked Questions
What is the JSON:API specification?▼
JSON:API is a standardized specification for building APIs in JSON. It defines exactly how resources, relationships, errors, and metadata should be structured in request and response bodies. By following a shared convention, clients and servers can interoperate without per-API custom documentation for basic CRUD operations.
What is the required Content-Type for JSON:API?▼
JSON:API requires the Content-Type header to be application/vnd.api+json for both requests and responses. Sending a plain application/json Content-Type header with a JSON:API body is technically non-conformant, though many implementations accept both in practice.
How does JSON:API handle relationships between resources?▼
Relationships are represented in a relationships object on the resource. Each relationship contains a data object with the related resource's type and id. The full related resource data can optionally be included in a top-level included array in the same response, which avoids N+1 requests from the client side.
What is sparse fieldsets in JSON:API?▼
Sparse fieldsets let clients request only specific fields of a resource using the fields[type]=field1,field2 query parameter. This reduces response payload size significantly for resources with many attributes, similar to how GraphQL lets you select specific fields in a query.
How does JSON:API pagination work?▼
JSON:API does not mandate a specific pagination strategy, but it standardizes the link objects returned: first, last, prev, and next. The server decides whether to use page-based (page[number]=2&page[size]=10), cursor-based, or offset-based pagination internally, and communicates navigation via the links object.
Is JSON:API suitable for every project?▼
JSON:API shines in larger applications with complex resource relationships, multiple client types (web, mobile, third-party), or teams that want a strict shared contract. For simple CRUD microservices with a single client, the verbosity of JSON:API may add overhead without proportional benefit. REST without a strict spec or tRPC is often simpler for small internal APIs.