- From: Gregg Kellogg <gregg@greggkellogg.net>
- Date: Thu, 28 Jul 2016 13:57:31 -0400
- To: Aymeric Brisse <aymeric.brisse@gmail.com>
- Cc: public-linked-json@w3.org
- Message-Id: <45EA9C4B-0CE5-4F02-9CBF-39F294360B8F@greggkellogg.net>
Hi Aymeric, you probably want to specify a JSON-LD Frame to the serializer to get the shape you want. You may need to manually get rid of a top-level @graph, but that would allow you to specify the shape of the result.
Gregg Kellogg
Sent from my iPad
> On Jul 28, 2016, at 1:39 PM, Aymeric Brisse <aymeric.brisse@gmail.com> wrote:
>
> 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:58:04 UTC