W3C home > Mailing lists > Public > public-linked-json@w3.org > July 2016

Re: JSON-LD & nested structure

From: Gregg Kellogg <gregg@greggkellogg.net>
Date: Fri, 29 Jul 2016 10:41:45 -0400
Cc: public-linked-json@w3.org
Message-Id: <FD1A9837-EC38-4B29-8965-385465C99348@greggkellogg.net>
To: Aymeric Brisse <aymeric.brisse@gmail.com>
> On Jul 29, 2016, at 8:44 AM, Aymeric Brisse <aymeric.brisse@gmail.com> wrote:
> 
> Hi Gregg,
> 
> Thanks for the reply. I played with the JSON-LD Frame feature and it is pretty cool. The problem is that it seems to be a "feature in progress" since it only works on some case:
> 
> ISSUE 110
> Currently, framing allows just to select node definitions based on @type matching or duck typing for included properties. It allows value properties to be explicitly matched based on defining the property and excluding things that are undefined, but it does not allow to be more specific about the types of values selected. Allowing this is currently being discussed.

Yes, it’s likely to remain in progress for a while, until the authors complete current projects, or new ones step forward. In fact, the spec now is at odds with existing implementations in minor ways.

> (Source: http://json-ld.org/spec/latest/json-ld-framing/ <http://json-ld.org/spec/latest/json-ld-framing/>)
> 
> In my case to specify a root entity I would like to be able to specify an @id filter instead of a @type (since my root entity can be linked to other entities of the same type)
> 
> frame = JSON.parse %({
>   "@context": {
>     ....
>   },
>   "@id": "http://www.myresource/uuid <http://www.myresource/uuid>"
> })
> 
> What would you recommend? Adding a fake rdf:type for the JSON-LD serialization and remove it after?

You can match on properties, so you might create a frame with the top-level item having a <http://www.myresource.com/ontology/1.0#talksAbout <http://www.myresource.com/ontology/1.0#talksAbout>> property, or inverse if that’s what you’re looking for.

Something like this:

{
  "@context": {
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "talksAbout": {"@id": "http://www.myresource.com/ontology/1.0#talksAbout", "@type": "@id"},
    "label": {"@id": "rdfs:label", "@language": "en"}
  },
  "talksAbout": {}
}

See this in the playground here: http://tinyurl.com/zuol7gv.

Gregg

> Thanks!
> 
> On Thu, Jul 28, 2016 at 7:57 PM, Gregg Kellogg <gregg@greggkellogg.net <mailto:gregg@greggkellogg.net>> wrote:
> 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 <mailto: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# <http://www.myresource.com/ontology/1.0#>' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns# <http://www.w3.org/1999/02/22-rdf-syntax-ns#>' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>'>
>>   <rdf:Description rdf:about='http://www.myresource/uuid <http://www.myresource/uuid>'>
>>     <ns0:talksAbout>
>>       <rdf:Description rdf:about='http://rdf.freebase.com/ns/m.018w8 <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 <http://rdf.greggkellogg.net/distiller>)
>> 
>> {
>>   "@context": {
>>     "rdfs": "http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>"
>>   },
>>   "@graph": [
>>     {
>>       "@id": "http://rdf.freebase.com/ns/m.018w8 <http://rdf.freebase.com/ns/m.018w8>",
>>       "rdfs:label": [
>>         {
>>           "@value": "Basketball",
>>           "@language": "en"
>>         }
>>       ]
>>     },
>>     {
>>       "@id": "http://www.myresource/uuid <http://www.myresource/uuid>",
>>       "http://www.myresource.com/ontology/1.0#talksAbout <http://www.myresource.com/ontology/1.0#talksAbout>": [
>>         {
>>           "@id": "http://rdf.freebase.com/ns/m.018w8 <http://rdf.freebase.com/ns/m.018w8>"
>>         }
>>       ]
>>     }
>>   ]
>> }
>> 
>> But I would like to obtain:
>> 
>> {
>>   "@context": {
>>     "rdfs": "http://www.w3.org/2000/01/rdf-schema# <http://www.w3.org/2000/01/rdf-schema#>"
>>   },
>>   "@id": "http://www.myresource/uuid <http://www.myresource/uuid>",
>>   "http://www.myresource.com/ontology/1.0#talksAbout <http://www.myresource.com/ontology/1.0#talksAbout>": [
>>       {
>>          "@id": "http://rdf.freebase.com/ns/m.018w8 <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 Friday, 29 July 2016 14:42:13 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:18:48 UTC