Skip to content

Instantly share code, notes, and snippets.

@Art4
Last active August 29, 2015 14:26
Show Gist options
  • Save Art4/a77052f1e8700bdde498 to your computer and use it in GitHub Desktop.
Save Art4/a77052f1e8700bdde498 to your computer and use it in GitHub Desktop.
Object structure of JSON API 1.0

JSON API Object Structure

Format: JSON API 1.0

This is a structure of all objects in a JSON API response body. This document will be used to build a JSON API Client in PHP. Please leave me a comment if there is something wrong or missing.

Note: This document covers only a possible JSON API response body. A request body can have some exceptions.

Symbols

Symbol Description
1 at least one of these properties is required
* zero, one or more properties
+ required
- optional
! not allowed

All objects

  1. Document object
  2. Resource Identifier object
  3. Resource object
  4. Attributes object
  5. Relationship Collection object
  6. Relationship object
  7. Error object
  8. Error Source object
  9. Link object
  10. Document Link object
  11. Relationship Link object
  12. Error Link object
  13. Pagination Link object
  14. Jsonapi object
  15. Meta object

Document object

  • extends:
  • extended by:
  • property of:

Properties

| Name | Value | Note

--- | ---- | ----- | ---- 1 | data | - null
- Resource Identifier object
- Resource object
- array()
- array(Resource Identifier object)
- array(Resource object) | not allowed, if 'errors' exists 1 | errors | array(Error object) | not allowed, if 'data' exists 1 | meta | Meta object |

Resource Identifier object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | type | string |
  • | id | string |

Resource object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Attributes object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | string | mixed | ! | type | | already used in Resource object | ! | id | | already used in Resource object | ! | relationships | | reserved by spec for future use | ! | links | | reserved by spec for future use |

Relationship Collection object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Relationship object

Properties

| Name | Value | Note

--- | ---- | ----- | ---- 1 | links | Relationship Link object | 1 | data | - null
- Resource Identifier object
- array()
- array(Resource Identifier object) | 1 | meta | Meta object |

Error object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Error Source object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | pointer | string |
  • | parameter | string |

Link object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Document Link object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Relationship Link object

Properties

| Name | Value | Note

--- | ---- | ----- | ---- 1 | self | string | 1 | related | string |

  • | pagination | Pagination Link object | Only exists if the parent relationship object represents a to-many relationship

Error Link object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

Pagination Link object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | first | - null
    - string |
  • | last | - null
    - string |
  • | prev | - null
    - string |
  • | next | - null
    - string |

Jsonapi object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | version | string | Default: "1.0"
  • | meta | Meta object |

Meta object

Properties

| Name | Value | Note

--- | ---- | ----- | ----

  • | string | mixed |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment