Presentation of JSON:API

Learn how to add JSON formatting rules to the application.

An essential and challenging part of creating our API is deciding the output format. Fortunately, some conventions already exist. Indeed, most the common come from JSON:API.

The JSON:API documentation gives us some rules to follow regarding formatting.

Our document must contain these keys:

  • data, which must contain the data we send back.
  • errors, which must contain an array of errors that have occurred.
  • meta, which contains a meta objectobjects containing non-standard meta-information about the link.

The content of the data key is also quite strict:

  • It must have a type key corresponding to the JSON model (an article, a user, and so on).
  • The properties of the objects must be placed in an attributes key.
  • The links of the objects must be placed in a relationships key.

Get hands-on with 1200+ tech skills courses.