Skip to content

How to include unknown keys in 'data' #558

@lode

Description

@lode

I'm writing an application which reads a potentially unknown database and outputs its using json:api. When outputting a resource, the data key (mostly) just contains the data from the database row. For the json:api format other special keys need to be added like id, type, links, etc. This conflicts when a database table contains such keys as columns. I.e. type is not uncommon as a table column and could mean something else than the resource type (i.e. table name).

I can imagine several ways to solve this conflict. AFAIK only the last variant is allowed according to the spec, but according to the human eye and sense, is also the most strange one.

{
    "data": {
        "id": 1,
        "type": "foo",
        "links": {},
        "resource": {
            "title": "...",
            "type": "...",
            "bio": "...",
        }
    }
}

{
    "data": {
        "_id": 1,
        "_type": "foo",
        "_links": {},
        "title": "...",
        "type": "...",
        "bio": "...",
    }
}

{
    "data": {
        "id": 1,
        "type": "foo",
        "links": {},
    },
    "meta": {
        "data": {
            "title": "...",
            "type": "...",
            "bio": "...",
        }
    }
}

Is there a common way to solve this problem? Or is json:api not really suited for this kind of usage?

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy