Discussion:
controlling JSON-LD output
Jim Balhoff
2014-08-11 19:03:38 UTC
Permalink
Hi,

I am trying to output a Model as JSON-LD. It's working fine, but now I would like to make some changes to how the output is structured. For example, I'd like to define a @reverse property in the @context so that I can output certain triples in the reverse direction. Is it possible to influence the output of the JSON-LD writer? I have not found a way.

Thank you,
Jim
Andy Seaborne
2014-08-12 14:20:24 UTC
Permalink
This post might be inappropriate. Click to display it.
Jim Balhoff
2014-08-13 15:14:52 UTC
Permalink
This post might be inappropriate. Click to display it.
Andy Seaborne
2014-08-13 20:19:53 UTC
Permalink
Post by Jim Balhoff
Post by Andy Seaborne
Post by Jim Balhoff
Hi,
I am trying to output a Model as JSON-LD. It's working fine, but
now I would like to make some changes to how the output is
reverse direction. Is it possible to influence the output of the
JSON-LD writer? I have not found a way.
Thank you, Jim
Jena uses java-jsonld to do the JSON-LD reading and writing. If
there is a way to control java-jsonld to do that then it can be
added (and I expect there is - I just don't know what it is).
There is a way to pass writer specific configuration details.
Currently, nothing is done but an obvious feature is to pass in the
context setup.
The Jena apart of the JSON writer is in
org.apache.jena.riot.out.JsonLDWriter
Would you like to have a look?
Yesterday I spent some time looking at jsonld-java. I added some code
to Jena so I could pass in a map for the context. This does get
the data is structured. So far I don't see how to guide the output so
that there is only one root object. I suspect I may be missing
something that could be done with the "compact" or "frame"
operations.
Best regards, Jim
Jim,

Thanks for trying. It's probably a question for jsonld-java directly.
Jena is using jsonld-java and maybe the writer is being too simplistic.
If there improvements, then I'm very willing to add them but when I
tried various options, I didn't get nicer output at the time. Maybe I
was missing something as well.

Andy
Jim Balhoff
2014-08-13 20:29:27 UTC
Permalink
Jim,
Thanks for trying. It's probably a question for jsonld-java directly. Jena is using jsonld-java and maybe the writer is being too simplistic. If there improvements, then I'm very willing to add them but when I tried various options, I didn't get nicer output at the time. Maybe I was missing something as well.
I think it's all a little more complex than I initially realized, but I know a bit more about JSON-LD now. :-) It seems like the way to manipulate the structure of the produced JSON-LD is via framing:

http://json-ld.org/spec/latest/json-ld-framing/

It might be nice for Jena to allow the user to provide a frame when writing JSON-LD. However in my case I wanted some triples to be serialized in the reverse direction, using the "@reverse" keyword (I have lots of triples with different subjects but the same object). But I don't think @reverse is handled yet in the framing algorithm:

https://github.com/json-ld/json-ld.org/issues/311

Best regards,
Jim
Andy Seaborne
2014-08-14 13:09:00 UTC
Permalink
Post by Jim Balhoff
Post by Andy Seaborne
Jim,
Thanks for trying. It's probably a question for jsonld-java
directly. Jena is using jsonld-java and maybe the writer is being
too simplistic. If there improvements, then I'm very willing to
add them but when I tried various options, I didn't get nicer
output at the time. Maybe I was missing something as well.
I think it's all a little more complex than I initially realized, but
I know a bit more about JSON-LD now. :-) It seems like the way to
http://json-ld.org/spec/latest/json-ld-framing/
It might be nice for Jena to allow the user to provide a frame when
writing JSON-LD.
Agreed.

The way to get information from the application is in Jena's "Context"
object (unrelated to JSON-LD's "@context"). The application is going to
have to be aware of JSON-LD details and maybe jsonld-java details but I
don't see that as avoidable.

Proposal:

Additional context keys:

jsonldContext
- value: the object expected for JsonLdProcessor.compact

jsonldFraming -
- value: the object expected for JsonLdProcessor.frame

if jsonldFraming is set
Then
JsonLdProcessor.frame
else
JsonLdProcessor.compact with jsonldContext.

Do you have an example (data, @context, frame) to use a development use
case?

Andy
Post by Jim Balhoff
However in my case I wanted some triples to be
have lots of triples with different subjects but the same object).
https://github.com/json-ld/json-ld.org/issues/311
Best regards, Jim
Thanks
Andy

Loading...