jsonld.js icon indicating copy to clipboard operation
jsonld.js copied to clipboard

A list of '@id'

Open cardinal27513 opened this issue 14 years ago • 4 comments

We use rdflib a while and used to serialize data to rdf/xml. There are multiple toplevel graphs in our data, like it is shown in below. There are two “<rdf:Description rdf:about=…/>” in the data set…

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:ns1="http://example.com/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
  <rdf:Description rdf:about="http://example.com/3">
    <rdf:type rdf:resource="http://example.com/ns#Verb_A"/>
    <ns1:hasChild rdf:resource="http://example.com/4"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.com/1">
    <rdf:type rdf:resource="http://example.com/ns#Verb_A"/>
    <ns1:hasChild rdf:resource="http://example.com/2"/>
  </rdf:Description>
</rdf:RDF>

When we try to serialize the same graph to json-ld using rdflib-jsonld serializer, (https://github.com/RDFLib/rdflib-jsonld), the top-level graphs are serialized as “@id” : [ {…} , {…}] I try this out from the playground and it complains that there is syntax error.

{"name":"jsonld.CompactError","message":"Could not expand input before compaction.","details":{"cause":{"name":"jsonld.SyntaxError","message":"Invalid JSON-LD syntax; "@id" value must a string.","details":{}}}}

So is this the bug in jsonld.js or the rdflib-jsonld ?
If the bug is in rdflib-jsonld, how should it serialize the data in such case???

{
  "@context": {
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@id": [
    {
      "@id": "http://example.com/3",
      "@type": "http://example.com/ns#Verb_A",
      "http://example.com/ns#hasChild": {
        "@id": "http://example.com/4"
      }
    },
    {
      "@id": "http://example.com/1",
      "@type": "http://example.com/ns#Verb_A",
      "http://example.com/ns#hasChild": {
        "@id": "http://example.com/2"
      }
    }
  ]
}

cardinal27513 avatar Apr 06 '12 01:04 cardinal27513

There was a recent change to the JSON-LD syntax that replaced the use of "@id" at the top-level to refer to disjoint or flattened graphs with "@graph". All you need to do is change the top-level "@id" to "@graph" and everything should work again. :)

dlongley avatar Apr 06 '12 01:04 dlongley

Just a meta-bug note that I edited your bug report and used the github markdown syntax for json and xml. It's much easier to read and write and no escaping by hand is needed. http://github.github.com/github-flavored-markdown/

davidlehn avatar Apr 06 '12 02:04 davidlehn

Thanks for the info. Can't find it in the April Draft.. in here http://json-ld.org/spec/latest/json-ld-syntax/

I guess that it will make its way to there soon.

cardinal27513 avatar Apr 06 '12 02:04 cardinal27513

The top-level '@id' should be changed to '@graph', the rdflib-jsonld implementation seems to be out of date. Here is a link to the JSON-LD playground with the example you have above converted to valid JSON-LD:

http://bit.ly/HSC23k

msporny avatar Apr 06 '12 02:04 msporny