- From: Mitar <mmitar@gmail.com>
- Date: Mon, 21 Mar 2016 05:26:19 -0700
- To: public-linked-json@w3.org
Hi! At the end, I decided to not use JSON Reference and just do: { "@context": { "@base": "http://127.0.0.1:8000/api/v2/node/", "@vocab": "http://127.0.0.1:8000/api/v2/node/?format=vocab#" }, "@type": "Node", "@id": "000c3d9d-5d7c-492a-8d3b-bb8b922ae35f", "config": { "core.location": { "@context": { "@base": "_:config/core.location/", "@vocab": "http://127.0.0.1:8000/api/v2/node/?format=vocab#config/core.location/" }, "@id": "123", "@type": "Location", "timezone": "Europe/Ljubljana", "address": "San Juan, Puerto Rico", "city": "Ljubljana", "country": "SI", "geolocation": { "@context": "http://geojson.org/contexts/geojson-base.jsonld", "type": "Point", "coordinates": [ -66.073756, 18.378287 ] }, "altitude": 0.0 }, "core.project": { "@context": { "@base": "_:config/core.project/", "@vocab": "http://127.0.0.1:8000/api/v2/node/?format=vocab#config/core.project/" }, "@id": "444", "@type": "Project", "project": "http://127.0.0.1:8000/api/v2/project/2" } } } Mitar On Wed, Mar 16, 2016 at 2:41 AM, Mitar <mmitar@gmail.com> wrote: > Hi! > > I have an issue how to combine JSON-LD and JSON reference in a meaningful way. > > For example, if I have internally many-to-many relation of devices, > which I represent as an array: > > { > "id": 333, > "devices": [ > { > "id": 123, > "name": "keyboard" > } > , > { > "id": 567, > "name": "mouse" > } > ], > "interfaces": [ > { > "id": 999, > "path": "key0", > "device": 123 > }, > { > "id": 897, > "path": "mouse0", > "device": 567 > } > ] > } > > So IDs come from the rows in the database. And now I would like to > convert this to something meaningful in JSON-LD, but to keep > references working. So I tried with this: > > { > "@id": "http://example.com/mapping/333", > "@base": "http://example.com/mapping/333", > "@context": "http://example.com/context", > "devices": [ > { > "@id": "#/devices/0", > "@type": "http://example.com/type/keyboard", > "name": "keyboard" > } > , > { > "@id": "#/devices/1", > "@type": "http://example.com/type/mouse", > "name": "mouse" > } > ], > "interfaces": [ > { > "@id": "#/interfaces/0, > "path": "key0", > "device": { > "$ref": "#/devices/0" > } > }, > { > "@id": "#/interfaces/1, > "path": "mouse0", > "device": { > "$ref": "#/devices/1" > } > } > ] > } > > So this looks like it has desired properties. Relative @id fields > nicely combine with @base, and $ref can reference those array elements > as well. The issue is that getting array index is very hard, > especially for references which point to documents not part of the > current query. It would be much better if one could reuse row IDs. > > But the issue is that JSON references support only array indexes, > nothing fancy like matching by @Id. > > I was thinking of extending JSON reference with @ syntax, to something like: > > > { > "@id": "http://example.com/mapping/333", > "@base": "http://example.com/mapping/333", > "@context": "http://example.com/context", > "devices": [ > { > "@id": "#/devices/@123", > "@type": "http://example.com/type/keyboard", > "name": "keyboard" > } > , > { > "@id": "#/devices/@567", > "@type": "http://example.com/type/mouse", > "name": "mouse" > } > ], > "interfaces": [ > { > "@id": "#/interfaces/@999, > "path": "key0", > "device": { > "$ref": "#/devices/@123" > } > }, > { > "@id": "#/interfaces/@897, > "path": "mouse0", > "device": { > "$ref": "#/devices/@567" > } > } > ] > } > > But it is unclear what exactly would be semantics of @ operator. Like, > to traverse the augmented JSON reference you traverse JSON object, and > then you get to @ you have to search for @id with the full reference > as a value? Strange definition. > > So what is a recommended way to address this? To have references, > which you can as needed dereference to fill with subdocuments. > > > Mitar > > -- > http://mitar.tnode.com/ > https://twitter.com/mitar_m -- http://mitar.tnode.com/ https://twitter.com/mitar_m
Received on Monday, 21 March 2016 12:26:50 UTC