Skip to content

Keys difference on JSON vs. JSON-LD #2066

Description

@er1z

I have a data created by custom data provider. Using JSON-LD the data looks like this:

{
  "@context": "/api/contexts/Struct",
  "@id": "/api/structs",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/api/structs/50c10eb8-ff18-4b02-9ca7-96c4efd78610",
      "@type": "Struct",
      "field1": "50c10eb8-ff18-4b02-9ca7-96c4efd78610",
      "field2": 1530690809
    },
    {
      "@id": "/api/structs/0f9f8409-08a7-4f52-bfa6-28bd91965ef0",
      "@type": "Struct",
      "field1": "0f9f8409-08a7-4f52-bfa6-28bd91965ef0",
      "field2": 1530690809
    },
    {
      "@id": "/api/structs/cf6e09ca-667e-4155-a7bd-c93369bedece",
      "@type": "Struct",
      "field1": "cf6e09ca-667e-4155-a7bd-c93369bedece",
      "field2": 1530690809
    },
    {
      "@id": "/api/structs/821920b5-bf87-474f-8d19-0ede22390b85",
      "@type": "Struct",
      "field1": "821920b5-bf87-474f-8d19-0ede22390b85",
      "field2": 1530690809
    }
  ],
  "hydra:totalItems": 4
}

Whereas using pure JSON produces:

{
  "1": {
    "field1": "27557fc5-7f22-4c67-992e-da999f89e303",
    "field2": 1530690972
  },
  "2": {
    "field1": "488b08c4-3aee-41f1-89c3-72c258cae9f6",
    "field2": 1530690972
  },
  "3": {
    "field1": "61559539-2a52-491a-8518-e495fcc30c78",
    "field2": 1530690972
  },
  "4": {
    "field1": "6903a099-42cb-4bf1-ace2-11a2244ee029",
    "field2": 1530690972
  }
}

How keys should look like? Implementing partial paginator enforces using iterator and yielding keys. Two questions:

  1. Which form is correct? Both with keys or neither?
  2. How to disable keys creation within pure JSON object and keep custom data provider with pagination?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions