Skip to content

JSONAPI Meta object should be at same level as Data, not inside it #248

@genyded

Description

@genyded

The JSONAPI spec at https://jsonapi.org/format/#document-meta shows the META object at the same level as the DATA object:

{
  "meta": {  //META IS OUTSIDE DATA
    "copyright": "Copyright 2015 Example Corp.",
    "authors": [
      "Yehuda Katz",
      "Steve Klabnik",
      "Dan Gebhardt",
      "Tyler Kellen"
    ]
  },
  "data": {
     //... 
  }
}

However Laravel JSONAPI seems to place the META object INSIDE the DATA object:

"data": {
        "type": "users",
        "id": "1",
        "attributes": {
            "firstName": "User",
            "lastName": "One",
            "email": "user1@email.com"
        },
        "relationships": {
            "profile": {
                "links": {
                    "related": "http://host.docker.internal/api/users/1/profile",
                    "self": "http://host.docker.internal/api/users/1/relationships/profile"
                }
            }
        },
        "links": {
            "self": "http://host.docker.internal/api/users/1"
        },
        "meta": {  // META IS INSIDE DATA
            "roles": [
                "super-admin"
            ]
        }
    },

While not a crisis, we're using some other stuff that populates some META info, and it put's it OUTSIDE the data object. So we end up with two META objects for the resource. Would it be possible to address this somehow? We can work around it, but the workaround involves manually manipulating the response body before sending and is a bit 'hacky'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions