RE: Web Linking in JSON-LD

On Saturday, September 28, 2013 6:55 PM, Ryan J. McDonough wrote:
> Just following up on the HAL example. I've been taking a look at the
> HAL+JSON example here:
> 
> http://stateless.co/hal_specification.html
> 
> And I've been looking to see how this might be expressed in terms of
> JSON-LD. As I stated in my initial email, it seems that the "_embedded"
> property could be expressed as named graphs. Here's a sample I hacked
> up:
> 
> {
>     "@context": {
>         "@vocab": "http://mashinator.io/2013/Linking#",
>         "xsd": "http://www.w3.org/2001/XMLSchema#",
[...]
>     },
>     "@graph": [  {
> 		"_default" : {
[...]
> 	}, {
> 		"_embedded": {
[...]
> 		}
> 	} ]
> }
> 
> I'm not so sure about the named graph labels, but I was merely trying
> to see how/if HAL could be expressed in JSON-LD.

This doesn't create two named graphs but puts two blank nodes, i.e., nodes
without an identifier, in the default graph. To create two named graphs, you
need a structure as follows:

{
  "@context": ...,
  "@graph": [
    {
      "@id": "named-graph-1",
      "@graph": [
        ... contents of the named graph ...
      ]
    },
    {
      "@id": "named-graph-2",
      "@graph": [
        ... contents of the named graph ...
      ]
    }
  ]
}


> As you've already
> pointed out,  HAL's "_embedded" resource offers much value since this
> is easily handled in JSON-LD already. It's a little more compact than
> the HAL version with the added benefit of being able to provide more
> detail about what the properties mean. But again, my motivations here
> are to see who to bridge the gap between something like HAL and JSON-LD
> as to illustrate how one would be able migrate to JSON-LD and/or Hydra.

I'm not sure I would model this with named graphs. Why do you need to
separate the statements about the /orders node from the /orders/123? I would
simply model it as follows:

{
  "@context": ...
  "@id: "/orders",
  "currentlyProcessing": 14,
  "shippedToday": 20,
  "next": "/orders?page=2",
  "ea:find": { "template": "/orders{?id}" },
  "ea:admin": [ 
    { "@id": "/admins/2", "title": "Fred" },
    { "@id": "/admins/5", "title": "Kate" }
  ],
  "ea:order": [
    {
      "@id": "/orders/123",
      "ea:basket": "/baskets/98712" ,
      "ea:customer": "/customers/7809"
      "total": 30.00,
      "currency": "USD",
      "status": "shipped"
    },
    {
      "@id": "/orders/124",
      "ea:basket": "/baskets/97213",
      "ea:customer": "/customers/12369"
      "total": 20.00,
      "currency": "USD",
      "status": "processing"
    }
  ]
}


HTH,
Markus


--
Markus Lanthaler
@markuslanthaler

Received on Sunday, 29 September 2013 17:00:06 UTC