json-ld.org icon indicating copy to clipboard operation
json-ld.org copied to clipboard

Datasets in JSON-LD are horriblely ugly and not navigable

Open gcarothers opened this issue 13 years ago • 6 comments

"@graph": [
{
  "@id": "http://example.org/graphs/1",
  "@graph": {
    "@id": "http://example.org/people/gavin",
    "http://example.com/vocab#name": "Gavin"
  }
},
{
  "@id": "http://example.org/graphs/2",
  "@graph": {
    "@id": "http://example.org/people/manu",
    "http://example.com/vocab#name": "Manu"
  }
},
{
  "@id": "http://example.org/graphs/3",
  "@graph": {
    "@id": "http://example.org/people/Lehn",
    "http://example.com/vocab#name": "Lehn"
  }
}]

}

The outer @graph is syntax cruft and has no meaning.

gcarothers avatar Jun 29 '13 00:06 gcarothers

Example from real data: https://gist.github.com/gcarothers/5889134 a replacement design might look like: https://gist.github.com/gcarothers/5889145 creating a @dataset which then uses normal JSON-LD keys to specify each graph.

gcarothers avatar Jun 29 '13 00:06 gcarothers

This could be useful in a separate spec, but it might not take a different keyword to do it. Something we didn't get to in 1.0 is the ability to have node definitions which are indexed from an object, rather than being in an array form; there are likely elements that could be added to a context which would indicate that the values of the object containing the context are to be treated as IDs, with their values the node definition (with an optional @id, which MUST resolve to the same IRI). This would pretty much eat the RDF/JSON use case. Doing this for graph names would be pretty similar.

This would be a nice JSON-LD 1.1 feature.

gkellogg avatar Jun 29 '13 01:06 gkellogg

If you don't mind a couple of extra triples you could do something like this:

{
  "@context": {
    "dataset": { "@id": "_:dataset", "@container": "@index" }
  },
  "dataset": {
    "http://example.org/graphs/1":
      {
        "@id": "http://example.org/graphs/1",
        "@graph": {
          "@id": "http://example.org/people/gavin",
          "http://example.com/vocab#name": "Gavin"
        }
      },
    "http://example.org/graphs/2":
      {
        "@id": "http://example.org/graphs/2",
        "@graph": {
          "@id": "http://example.org/people/manu",
          "http://example.com/vocab#name": "Manu"
        }
      },
    "http://example.org/graphs/3":
      {
        "@id": "http://example.org/graphs/3",
        "@graph": {
          "@id": "http://example.org/people/Lehn",
          "http://example.com/vocab#name": "Lehn"
        }
      }
  }
}

The outer @graph is syntax cruft and has no meaning.

You don't need to use it if you don't need to specify a context at the same time:

[
  {
    "@id": "http://example.org/graphs/1",
    "@graph": {
      "@id": "http://example.org/people/gavin",
      "http://example.com/vocab#name": "Gavin"
    }
  },
  ...
]

is valid as well.

lanthaler avatar Jun 30 '13 16:06 lanthaler

This is likely solved using the @container: @graph proposal from #195; this would certainly make datasets more navigable.

gkellogg avatar Oct 19 '16 06:10 gkellogg

I propose closing this with no change; please 👍 or 👎 to close.

gkellogg avatar Apr 08 '17 21:04 gkellogg

Seems like #481 and #195 address this concern.

gkellogg avatar May 04 '17 00:05 gkellogg