digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.64k stars 195 forks source link

Example 9 has different results in the playground #525

Open wouterbeek opened 1 year ago

wouterbeek commented 1 year ago

Example 8 in the standard document looks very different in the JSON-LD Playground (accessed through the "Open in playground" button from the standard document). This is example 8:

{
  "@context": {"@vocab": "http://example.org/"},
  "location": {},
  "contains": {
    "creator": {},
    "contains": {
      "description": {}
    }
  }
}

In the standard, it looks as follows:

{
  "@context": {"@vocab": "http://example.org/"},
  "@id": "http://example.org/library",
  "@type": "Library",
  "location": "Athens",
  "contains": {
    "@id": "http://example.org/library/the-republic",
    "@type": "Book",
    "creator": "Plato",
    "title": "The Republic",
    "contains": {
      "@id": "http://example.org/library/the-republic#introduction",
      "@type": "Chapter",
      "description": "An introductory chapter on The Republic.",
      "title": "The Introduction"
    }
  }
}

But in JSON-LD Playground, it looks as follows:

{
  "@context": {
    "@vocab": "http://example.org/"
  },
  "@graph": [
    {
      "@id": "http://example.org/library",
      "@type": "Library",
      "contains": {
        "@id": "http://example.org/library/the-republic",
        "@type": "Book",
        "contains": {
          "@id": "http://example.org/library/the-republic#introduction",
          "@type": "Chapter",
          "description": "An introductory chapter on The Republic.",
          "title": "The Introduction"
        },
        "creator": "Plato",
        "title": "The Republic"
      },
      "location": "Athens"
    },
    {
      "@id": "http://example.org/library/the-republic",
      "@type": "Book",
      "contains": null,
      "creator": "Plato",
      "location": null,
      "title": "The Republic"
    }
  ]
}

^ Notice that the use of @graph and null, together with the repetition of the values "Book', "Plato", and "The Republic", makes this snippet uglier than the one in the standard document

This is the live link to the playground: link

Expected

The same example to look identical (or at least more similar) in the document and in the playground.

wouterbeek commented 1 year ago

A similar issue occurs for Example 14, this looks as follows in the JSON-LD Playground (again: uglier because of @graph and null):

{
  "@context": {
    "@version": 1.1,
    "@vocab": "http://example.org/"
  },
  "@graph": [
    {
      "@id": "http://example.org/library",
      "@type": "Library",
      "contains": {
        "@id": "http://example.org/library/the-republic",
        "@type": "Book",
        "contains": {
          "@id": "http://example.org/library/the-republic#introduction",
          "@type": "Chapter",
          "description": "An introductory chapter on The Republic.",
          "title": "The Introduction"
        },
        "creator": {
          "@language": "el-latn",
          "@value": "Plátōn"
        },
        "title": {
          "@language": "el-latn",
          "@value": "Res Publica"
        }
      },
      "location": {
        "@language": "el-latn",
        "@value": "Athína"
      }
    },
    {
      "@id": "http://example.org/library/the-republic",
      "@type": "Book",
      "contains": null,
      "creator": [
        {
          "@language": "el-latn",
          "@value": "Plátōn"
        },
        {
          "@language": "grc",
          "@value": "Πλάτων"
        },
        {
          "@language": "en",
          "@value": "Plato"
        }
      ],
      "location": null,
      "title": [
        {
          "@language": "grc",
          "@value": "Πολιτεία"
        },
        {
          "@language": "el-latn",
          "@value": "Res Publica"
        },
        {
          "@language": "en",
          "@value": "The Republic"
        }
      ]
    }
  ]
}