w3c / json-ld-syntax

JSON-LD 1.1 Specification
https://w3c.github.io/json-ld-syntax/
Other
114 stars 22 forks source link

[Question] How to do an array of arrays in a JSON-LD @context #414

Open melvincarvalho opened 1 year ago

melvincarvalho commented 1 year ago

Hi All

I need to create a context that models an array of arrays, and I was wondering how to do it.

Possibility 1: "tags": {"@container": "@list", "@type": "@list" }

{
  "@context": {
    "@version": 1.1,
    "@vocab": "http://example.org/",
    "tags": {
      "@container": "@list",
      "@type": "@list"
    }
  },
  "tags": [
    ["A", "B", "C"],
    ["D", "E", "F"],
    ["G", "H", "I"]
  ]
}

Possibility 2: "tags": {"@container": "@list"}

{
  "@context": {
    "@vocab": "http://example.org/",
    "tags": {"@container": "@list"}
  },
  "tags": [
    ["A", "B", "C"],
    ["D", "E", "F"],
    ["G", "H", "I"]
  ]
}

Possibility 3: Other (?)

Any help greatly appreciated

TallTed commented 1 year ago

@melvincarvalho — Please return to your initial post, and code fence all the @blah entities, so those users are not spammed by comments on a thread they've not chosen to join...

That is, change Possibility 1: "tags": {"@container": "@list", "@type": "@list" } to Possibility 1: `"tags": {"@container": "@list", "@type": "@list" }` and Possibility 2: tags": {"@container": "@list"} to Possibility 2: `"tags": {"@container": "@list"}`

(Note -- Your Possibility 2 also lacks an opening quote on tags", which I've included in my suggested change, above.)

Peeja commented 1 year ago

@melvincarvalho Your Possibility 2 seems to work just fine. That models it as a list of lists. If you'd prefer to model them as a JSON array of JSON arrays, you can use {"@type": "@json"} instead.

VladimirAlexiev commented 5 days ago

Related: #428