Re: How to skip flattening when serializing RDF::Graph to JSON-LD?

Hi Gregg,

indeed, JSON-LD Framing achieves this goal. Thanks for a quick response.

For this simple purpose, it suffices to pass in a frame that states what
the top-level object's type should be. For example, the following code does
the job if the top-level object is an instance of schema:JobPosting:

frame = {
  "@context" => {
    "@vocab" => "http://schema.org/"
  },
  "@type" => "JobPosting"
}
framed_jsonld = JSON::LD::API.frame(jsonld, frame)

However, I have to admit that I haven't really studied JSON-LD Framing spec
(http://json-ld.org/spec/latest/json-ld-framing/). As one of its issues
states, some parts of the spec seem "about as clear as mud" and they would
likely benefit from examples of JSON-LD frames. Fortunately, I've found
several examples of JSON-LD frames in the JSON-LD mailing list (
http://lists.w3.org/Archives/Public/public-linked-json/2011Sep/0002.html).

Best,

Jindřich

-- 
Jindřich Mynarz
http://mynarz.net/#jindrich


On Tue, Jun 3, 2014 at 4:03 PM, Gregg Kellogg <gregg@greggkellogg.net>
wrote:

> On Jun 3, 2014, at 6:33 AM, Jindřich Mynarz <mynarzjindrich@gmail.com>
> wrote:
>
> Hi,
>
> when using JSON-LD writer, is it possible to skip flattening (
> http://www.w3.org/TR/json-ld-api/#flattening-algorithm)? I'd like to see
> objects identified with blank nodes as nested in the resulting JSON instead
> of being inserted as top-level objects in the JSON-LD @graph. This is what
> PyRDFa (http://www.w3.org/2012/pyRdfa/) distiller does when JSON-LD
> output is requested. Is this possible with the json/ld gem?
>
>
> The algorithm doesn't use flattening, but the result is pretty much the
> same. Easiest to frame the result to get the specific hierarchy you want.
>
> As an enhancement, the writer _could_ auto-frame, much as the Turtle
> writer does, but this would require a fair bit of work. But, framing should
> get you what you want, for some specific frame.
>
> Gregg
>
> I've consulted the library's documentation (
> http://rubydoc.info/gems/json-ld/file/README.md), but I haven't found an
> answer.
>
> Best,
>
> Jindřich
>
> --
> Jindřich Mynarz
> http://mynarz.net/#jindrich
>
>

Received on Tuesday, 3 June 2014 14:56:23 UTC