Specification v1.0 (Archived Copy)
Status
This page presents an archived copy of JSON:API version 1.0. None of the normative text on this page will change. While 1.0 is no longer the latest version of JSON:API, new versions will remain compatible with this one, as JSON:API uses a never remove, only add strategy.
If you catch an error in the specification’s text, or if you write an implementation, please let us know by opening an issue or pull request at our GitHub repository.
Introduction
JSON:API is a specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests.
JSON:API is designed to minimize both the number of requests and the amount of data transmitted between clients and servers. This efficiency is achieved without compromising readability, flexibility, or discoverability.
JSON:API requires use of the JSON:API media type
(application/vnd.api+json)
for exchanging data.
Conventions
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119 [RFC2119].
Content Negotiation
Client Responsibilities
Clients MUST send all JSON:API data in request documents with the header
Content-Type: application/vnd.api+json without any media type parameters.
Clients that include the JSON:API media type in their Accept header MUST
specify the media type there at least once without any media type parameters.
Clients MUST ignore any parameters for the application/vnd.api+json
media type received in the Content-Type header of response documents.
Server Responsibilities
Servers MUST send all JSON:API data in response documents with the header
Content-Type: application/vnd.api+json without any media type parameters.
Servers MUST respond with a 415 Unsupported Media Type status code if
a request specifies the header Content-Type: application/vnd.api+json
with any media type parameters.
Servers MUST respond with a 406 Not Acceptable status code if a
request’s Accept header contains the JSON:API media type and all instances
of that media type are modified with media type parameters.
Note: The content negotiation requirements exist to allow future versions of this specification to use media type parameters for extension negotiation and versioning.
Document Structure
This section describes the structure of a JSON:API document, which is identified
by the media type application/vnd.api+json.
JSON:API documents are defined in JavaScript Object Notation (JSON)
[RFC7159].
Although the same media type is used for both request and response documents, certain aspects are only applicable to one or the other. These differences are called out below.
Unless otherwise noted, objects defined by this specification MUST NOT contain any additional members. Client and server implementations MUST ignore members not recognized by this specification.
Note: These conditions allow this specification to evolve through additive changes.
Top Level
A JSON object MUST be at the root of every JSON:API request and response containing data. This object defines a document’s “top level”.
A document MUST contain at least one of the following top-level members:
data: the document’s “primary data”errors: an array of error objectsmeta: a meta object that contains non-standard meta-information.
The members data and errors MUST NOT coexist in the same document.
A document MAY contain any of these top-level members:
jsonapi: an object describing the server’s implementationlinks: a links object related to the primary data.included: an array of resource objects that are related to the primary data and/or each other (“included resources”).
If a document does not contain a top-level data key, the included member
MUST NOT be present either.
The top-level links object MAY contain the following members:
self: the link that generated the current response document.related: a related resource link when the primary data represents a resource relationship.- pagination links for the primary data.
The document’s “primary data” is a representation of the resource or collection of resources targeted by a request.
Primary data MUST be either:
- a single resource object, a single resource identifier object, or
null, for requests that target single resources - an array of resource objects, an array of
resource identifier objects, or
an empty array (
[]), for requests that target resource collections
For example, the following primary data is a single resource object:
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
// ... this article's attributes
},
"relationships": {
// ... this article's relationships
}
}
}
The following primary data is a single resource identifier object that references the same resource:
{
"data": {
"type": "articles",
"id": "1"
}
}
A logical collection of resources MUST be represented as an array, even if it only contains one item or is empty.
Resource Objects
“Resource objects” appear in a JSON:API document to represent resources.
A resource object MUST contain at least the following top-level members:
idtype
Exception: The id member is not required when the resource object originates at
the client and represents a new resource to be created on the server.
In addition, a resource object MAY contain any of these top-level members:
attributes: an attributes object representing some of the resource’s data.relationships: a relationships object describing relationships between the resource and other JSON:API resources.links: a links object containing links related to the resource.meta: a meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
Here’s how an article (i.e. a resource of type “articles”) might appear in a document:
// ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"links": {
"self": "/articles/1/relationships/author",
"related": "/articles/1/author"
},
"data": { "type": "people", "id": "9" }
}
}
}
// ...
Identification
Every resource object MUST contain an id member and a type member.
The values of the id and type members MUST be strings.
Within a given API, each resource object’s type and id pair MUST
identify a single, unique resource. (The set of URIs controlled by a server,
or multiple servers acting as one, constitute an API.)
The type member is used to describe resource objects that share common
attributes and relationships.
The values of type members MUST adhere to the same constraints as
member names.
Note: This spec is agnostic about inflection rules, so the value of
typecan be either plural or singular. However, the same value should be used consistently throughout an implementation.
Fields
A resource object’s attributes and its relationships are collectively called its “fields”.
Fields for a resource object MUST share a common namespace with each
other and with type and id. In other words, a resource can not have an
attribute and relationship with the same name, nor can it have an attribute
or relationship named type or id.
Attributes
The value of the attributes key MUST be an object (an “attributes
object”). Members of the attributes object (“attributes”) represent information
about the resource object in which it’s defined.
Attributes may contain any valid JSON value.
Complex data structures involving JSON objects and arrays are allowed as
attribute values. However, any object that constitutes or is contained in an
attribute MUST NOT contain a relationships or links member, as those
members are reserved by this specification for future use.
Although has-one foreign keys (e.g. author_id) are often stored internally
alongside other information to be represented in a resource object, these keys
SHOULD NOT appear as attributes.
Note: See fields and member names for more restrictions on this container.
Relationships
The value of the relationships key MUST be an object (a “relationships
object”). Members of the relationships object (“relationships”) represent
references from the resource object in which it’s defined to other resource
objects.
Relationships may be to-one or to-many.
A “relationship object” MUST contain at least one of the following:
links: a links object containing at least one of the following:self: a link for the relationship itself (a “relationship link”). This link allows the client to directly manipulate the relationship. For example, removing anauthorthrough anarticle’s relationship URL would disconnect the person from thearticlewithout deleting thepeopleresource itself. When fetched successfully, this link returns the linkage for the related resources as its primary data. (See Fetching Relationships.)related: a related resource link
data: resource linkagemeta: a meta object that contains non-standard meta-information about the relationship.
A relationship object that represents a to-many relationship MAY also contain
pagination links under the links member, as described below. Any
pagination links in a relationship object MUST paginate the relationship
data, not the related resources.
Note: See fields and member names for more restrictions on this container.
Related Resource Links
A “related resource link” provides access to resource objects linked in a relationship. When fetched, the related resource object(s) are returned as the response’s primary data.
For example, an article’s comments relationship could
specify a link that returns a collection of comment resource objects
when retrieved through a GET request.
If present, a related resource link MUST reference a valid URL, even if the relationship isn’t currently associated with any target resources. Additionally, a related resource link MUST NOT change because its relationship’s content changes.
Resource Linkage
Resource linkage in a compound document allows a client to link together all
of the included resource objects without having to GET any URLs via links.
Resource linkage MUST be represented as one of the following:
nullfor empty to-one relationships.- an empty array (
[]) for empty to-many relationships. - a single resource identifier object for non-empty to-one relationships.
- an array of resource identifier objects for non-empty to-many relationships.
Note: The spec does not impart meaning to order of resource identifier objects in linkage arrays of to-many relationships, although implementations may do that. Arrays of resource identifier objects may represent ordered or unordered relationships, and both types can be mixed in one response object.
For example, the following article is associated with an author:
// ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/articles/1"
}
}
// ...
The author relationship includes a link for the relationship itself (which
allows the client to change the related author directly), a related resource
link to fetch the resource objects, and linkage information.
Resource Links
The optional links member within each resource object contains links
related to the resource.
If present, this links object MAY contain a self link that
identifies the resource represented by the resource object.
// ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"links": {
"self": "http://example.com/articles/1"
}
}
// ...
A server MUST respond to a GET request to the specified URL with a
response that includes the resource as the primary data.
Resource Identifier Objects
A “resource identifier object” is an object that identifies an individual resource.
A “resource identifier object” MUST contain type and id members.
A “resource identifier object” MAY also include a meta member, whose value is a meta object that
contains non-standard meta-information.
Compound Documents
To reduce the number of HTTP requests, servers MAY allow responses that include related resources along with the requested primary resources. Such responses are called “compound documents”.
In a compound document, all included resources MUST be represented as an
array of resource objects in a top-level included member.
Compound documents require “full linkage”, meaning that every included resource MUST be identified by at least one resource identifier object in the same document. These resource identifier objects could either be primary data or represent resource linkage contained within primary or included resources.
The only exception to the full linkage requirement is when relationship fields that would otherwise contain linkage data are excluded via sparse fieldsets.
Note: Full linkage ensures that included resources are related to either the primary data (which could be resource objects or resource identifier objects) or to each other.
A complete example document with multiple included relationships:
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!"
},
"links": {
"self": "http://example.com/articles/1"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
},
"comments": {
"links": {
"self": "http://example.com/articles/1/relationships/comments",
"related": "http://example.com/articles/1/comments"
},
"data": [
{ "type": "comments", "id": "5" },
{ "type": "comments", "id": "12" }
]
}
}
}],
"included": [{
"type": "people",
"id": "9",
"attributes": {
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"links": {
"self": "http://example.com/people/9"
}
}, {
"type": "comments",
"id": "5",
"attributes": {
"body": "First!"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "2" }
}
},
"links": {
"self": "http://example.com/comments/5"
}
}, {
"type": "comments",
"id": "12",
"attributes": {
"body": "I like XML better"
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/comments/12"
}
}]
}
A compound document MUST NOT include more than one resource object for
each type and id pair.
Note: In a single document, you can think of the
typeandidas a composite key that uniquely references resource objects in another part of the document.
Note: This approach ensures that a single canonical resource object is returned with each response, even when the same resource is referenced multiple times.
Meta Information
Where specified, a meta member can be used to include non-standard
meta-information. The value of each meta member MUST be an object (a
“meta object”).
Any members MAY be specified within meta objects.
For example:
{
"meta": {
"copyright": "Copyright 2015 Example Corp."