Latest Specification (v1.1)
Status
This page presents the latest published version of JSON:API, which is currently version 1.1. New versions of JSON:API will always be backwards compatible using a never remove, only add strategy. Additions can be proposed in our discussion forum.
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 can be easily extended with extensions and profiles.
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.
Semantics
All document members, query parameters, and processing rules defined by this specification are collectively called “specification semantics”.
Certain document members, query parameters, and processing rules are reserved for implementors to define at their discretion. These are called “implementation semantics”.
All other semantics are reserved for potential future use by this specification.
Conventions
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
The JSON:API Media Type
The JSON:API media type is
application/vnd.api+json.
Media Type Parameters
The JSON:API specification supports two media type parameters: ext and
profile, which are used to specify extensions and profiles, respectively.
Note: A media type parameter is an extra piece of information that can accompany a media type. For example, in the header
Content-Type: text/html;charset="utf-8", the media type istext/htmlandcharsetis a parameter.
Extensions
Extensions provide a means to “extend” the base specification by defining additional specification semantics.
Extensions cannot alter or remove specification semantics, nor can they specify implementation semantics.
Profiles
Profiles provide a means to share a particular usage of the specification among implementations.
Profiles can specify implementation semantics, but cannot alter, add to, or remove specification semantics.
Rules for Media Type Parameters
The JSON:API media type MUST NOT be specified with any media type parameters
other than ext and profile. The ext parameter is used to support
extensions and the profile parameter is used to support profiles.
Extensions and profiles are each uniquely identified by a
URI. Visiting an extension’s or a
profile’s URI SHOULD return documentation that describes its usage. The
values of the ext and profile parameters MUST equal a space-separated
(U+0020 SPACE, “ “) list of extension or profile URIs, respectively.
Note: When serializing the
extorprofilemedia type parameters, the HTTP specification requires that parameter values be surrounded by quotation marks (U+0022 QUOTATION MARK, “"”).
Rules for Extensions
An extension MAY impose additional processing rules or further restrictions and it MAY define new object members as described below.
An extension MUST NOT lessen or remove any processing rules, restrictions or object member requirements defined in this specification or other extensions.
An extension MAY define new members within the document structure defined by this specification. The rules for extension member names are covered below.
An extension MAY define new query parameters. The rules for extension-defined query parameters are covered below.
When an extension defines new query parameters or document members, the extension MUST define a namespace to guarantee that extensions will never conflict with current or future versions of this specification. A namespace MUST meet all of the following conditions:
- A namespace MUST contain at least one character.
- A namespace MUST contain only these characters:
- U+0061 to U+007A, “a-z”
- U+0041 to U+005A, “A-Z”
- U+0030 to U+0039, “0-9”
An extension MUST NOT define more than one namespace. The namespace used for all query parameters and document members MUST be the same for any given extension.
In the following example, an extension with the namespace version has
specified a resource object member version:id to support per-resource
versioning. This member might appear as follows:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/version"
// ...
{
"type": "articles",
"id": "1",
"version:id": "42",
"attributes": {
"title": "Rails is Omakase"
}
}
// ...
Rules for Profiles
The rules for profile usage are dictated by RFC 6906.
A profile MAY define document members and processing rules that are reserved for implementors.
A profile MUST NOT define any query parameters except implementation-specific query parameters.
A profile MUST NOT alter or remove processing rules that have been defined by this specification or by an extension. However, a profile MAY define processing rules for query parameters whose processing rules have been reserved for implementors to define at their discretion.
For example, a profile could define rules for interpreting the filter query
parameter, but it could not specify that relationship
names in the include query parameter are
space-separated instead of dot-separated.
Unlike extensions, profiles do not need to define a namespace for document members because profiles cannot define specification semantics and thus cannot conflict with current or future versions of this specification. However, it is possible for profiles to conflict with other profiles. Therefore, it is the responsibility of implementors to ensure that they do not support conflicting profiles.
In the following example, a profile has defined a timestamps
attribute. According to the profile, the attribute must be an
object containing a created member and a modified member and these members’
values must use the RFC 3339 format.
With such a profile applied, a response might appear as follows:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json;profile="https://example.com/resource-timestamps"
// ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase",
"timestamps": {
"created": "2020-07-21T12:09:00Z",
"modified": "2020-07-30T10:19:01Z"
}
}
}
// ...
Content Negotiation
Universal Responsibilities
Clients and servers MUST send all JSON:API payloads using the JSON:API media
type in the Content-Type header.
Clients and servers MUST specify the ext media type parameter in the
Content-Type header when they have applied one or more extensions to a
JSON:API document.
Clients and servers MUST specify the profile media type parameters in the
Content-Type header when they have applied one or more profiles to a JSON:API
document.
Client Responsibilities
When processing a JSON:API response document, clients MUST ignore any
parameters other than ext and profile parameters in the server’s
Content-Type header.
A client MAY use the ext media type parameter in an Accept header to
require that a server apply all the specified extensions to the response
document.
A client MAY use the profile media type parameter in an Accept header
to request that the server apply one or more profiles to the response document.
Note: A client is allowed to send more than one acceptable media type in the
Acceptheader, including multiple instances of the JSON:API media type. This allows clients to request different combinations of theextandprofilemedia type parameters. A client can use quality values to indicate that some combinations are less preferable than others. Media types specified without a qvalue are equally preferable to each other, regardless of their order, and are always considered more preferable than a media type with a qvalue less than 1.
Server Responsibilities
If a request specifies the Content-Type header with the JSON:API media type,
servers MUST respond with a 415 Unsupported Media Type status code if
that media type contains any media type parameters other than ext or
profile.
If a request specifies the Content-Type header with an instance of
the JSON:API media type modified by the ext media type parameter and that
parameter contains an unsupported extension URI, the server MUST respond
with a 415 Unsupported Media Type status code.
Note: JSON:API servers that do not support version 1.1 of this specification will respond with a
415 Unsupported Media Typeclient error if theextorprofilemedia type parameter is present.
If a request’s Accept header contains an instance of the JSON:API media type,
servers MUST ignore instances of that media type which are modified by a
media type parameter other than ext or profile. If all instances of that
media type are modified with a media type parameter other than ext or profile,
servers MUST respond with a 406 Not Acceptable status code. If every
instance of that media type is modified by the ext parameter and each contains
at least one unsupported extension URI, the server MUST also respond with a
406 Not Acceptable.
If the profile parameter is received, a server SHOULD attempt to apply any
requested profile(s) to its response. A server MUST ignore any profiles
that it does not recognize.
Note: The above rules guarantee strict agreement on extensions between the client and server, while the application of profiles is left to the discretion of the server.
Servers that support the ext or profile media type parameters SHOULD
specify the Vary header with Accept as one of its values. This applies to
responses with and without any profiles or extensions applied.
Note: Some HTTP intermediaries (e.g. CDNs) may ignore the
Varyheader unless specifically configured to respect it.
Document Structure
This section describes the structure of a JSON:API document, which is identified by the JSON:API media type. JSON:API documents are defined in JavaScript Object Notation (JSON) [RFC8259].
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.
Extensions MAY define new members within the document structure. These members MUST comply with the naming requirements specified below.
Unless otherwise noted, objects defined by this specification or any applied extensions MUST NOT contain any additional members. Client and server implementations MUST ignore non-compliant members.
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 document 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 objects.meta: a meta object that contains non-standard meta-information.- a member defined by an applied extension.
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 implementation.links: a links object related to the document as a whole.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. If a document has extensions or profiles applied to it, this link SHOULD be represented by a link object with thetypetarget attribute specifying the JSON:API media type with all applicable parameters.related: a related resource link when the primary data represents a resource relationship.describedby: a link to a description document (e.g. OpenAPI or JSON Schema) for the current document.- pagination links for the primary data.
Note: The
selflink in the top-levellinksobject allows a client to refresh the data represented by the current response document. The client should be able to use the provided link without applying any additional information. Therefore the link must contain the query parameters provided by the client to generate the response document. This includes but is not limited to query parameters used for inclusion of related resources, sparse fieldsets, sorting, pagination and filtering.
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 that
case, a client MAY include a lid member to uniquely identify the resource
by type locally within the document.
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
As noted above, every resource object MUST contain a
type member. Every resource object MUST also contain an id member,
except when the resource object originates at the client and represents a new
resource to be created on the server. If id is omitted due to this exception,
a lid member MAY be included to uniquely identify the resource by type
locally within the document. The value of the lid member MUST be
identical for every representation of the resource in the document, including
resource identifier objects.
The values of the id, type, and lid 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, including complex data structures involving JSON objects and arrays.
Keys that reference related resources (e.g. author_id) SHOULD NOT appear
as attributes. Instead, relationships SHOULD be used.
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”). Each member of a relationships object represents
a “relationship” from the resource object
in which it has been defined to other resource objects.
Relationships may be to-one or to-many.
A relationship’s name is given by its key. The value at that key MUST be an object (“relationship object”).
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- a member defined by an applied extension.
data: resource linkagemeta: a meta object that contains non-standard meta-information about the relationship.- a member defined by an applied extension.
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" }
}