JSONAPI: is it correct to have different types in data[]?

363 views Asked by At

is it correct to have different types in data array ? didn't found answer in specification, but looks wrong.

{
  "data": [
    {
      "type": "type1",
      "id": "id1"
    },

    {
      "type": "type2",
      "id": "id2"
    }
  ]
}
1

There are 1 answers

1
jelhan On

Polymorphic collections are supported by JSON:API specification. Your example is a valid JSON:API document.

This is not mentioned explicitly in the specification. It is only implicitly stated by not requiring all resource objects included as primary data to have the same type.

Please note that it could even include two resource objects with the same id as long as they have different type.