JSON-LD & nested structure

Hello,

I am currently working on a API that would return some JSON-LD and face
some problematic. I would like to know, when transforming a graph to
JSON-LD, how to be able to avoid the @graph object generation and having a
nested hash instead (I assume that I have a root element).

The idea is to have a structure more *traditional* for the developers that
want to parse it as a simple JSON object.

Let's say I have to following graph (rdf/xml for readability):

<?xml version='1.0' encoding='utf-8' ?>
<rdf:RDF xmlns:ns0='http://www.myresource.com/ontology/1.0#' xmlns:rdf='
http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='
http://www.w3.org/2000/01/rdf-schema#'>
  <rdf:Description rdf:about='http://www.myresource/uuid'>
    <ns0:talksAbout>
      <rdf:Description rdf:about='http://rdf.freebase.com/ns/m.018w8'>
        <rdfs:label xml:lang='en'>Basketball</rdfs:label>
      </rdf:Description>
    </ns0:talksAbout>
  </rdf:Description>
</rdf:RDF>

Basically when I use a standard serializer like the jsonld gem in Ruby to
serialize it in JSON-LD I obtain (reproducible on
http://rdf.greggkellogg.net/distiller)

{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@graph": [
    {
      "@id": "http://rdf.freebase.com/ns/m.018w8",
      "rdfs:label": [
        {
          "@value": "Basketball",
          "@language": "en"
        }
      ]
    },
    {
      "@id": "http://www.myresource/uuid",
      "http://www.myresource.com/ontology/1.0#talksAbout": [
        {
          "@id": "http://rdf.freebase.com/ns/m.018w8"
        }
      ]
    }
  ]
}

But I would like to obtain:

{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
  },
  "@id": "http://www.myresource/uuid",
  "http://www.myresource.com/ontology/1.0#talksAbout": [
      {
         "@id": "http://rdf.freebase.com/ns/m.018w8",
         "rdfs:label": [
           {
             "@value": "Basketball",
             "@language": "en"
           }
         ]
     }
  ]
}

Is there any option or way to do it?

Thanks!

Received on Thursday, 28 July 2016 17:40:46 UTC