Combining JSON-LD and JSON reference

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

Received on Wednesday, 16 March 2016 09:41:35 UTC