You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by François-Paul Servant <fr...@gmail.com> on 2016/04/10 16:43:45 UTC

Controlling JSON-LD output

Hi,

beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context. 

If not, any pointer into the code to get me started quickly?

I’ve read this old thread on this subject:
http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output

Best,

fps



Re: Controlling JSON-LD output

Posted by François-Paul Servant <fr...@gmail.com>.
good idea, thanks. The availability of the more “advanced” parameters could maybe then depend on the variant: for instance, there is no context to provide when the output form is “expand”

fps

> Le 12 avr. 2016 à 11:11, Rob Vesse <rv...@dotnetrdf.org> a écrit :
> 
> Another option to provide a more basic customisation is to simply define several language variants as is done with turtle currently where each variant would be mapped to a JSOn-LD writer with some appropriate default settings.
> 
> So for example you might have a compacted variant which would configure the writer to output compact output
> 
> 
> 
> On 12/04/2016 09:36, "François-Paul Servant" <fr...@gmail.com> wrote:
> 
>> Hi,
>> 
>>> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)
>> 
>> “general, robust and pretty” is probably to hard for me, but I could try something.
>> 
>> I have looked at the code.
>> 
>> Regarding robustness, one difficulty comes from the fact that jsonld-java uses Object as type of most of its arguments in methods
>> 
>> Andy, following your suggestions in the thread already mentioned:
>> 
>> It looks like there is no write methods with the (jena) Context argument in RDFDataMgr, so it would be necessary to add them.
>> 
>> Then there is the question of the stuff that we want to use to control the output by jsonld-java. Andy, you suggested to give the possibility to pass the (jsonld-java) context, and the frame object expected by the framing algo.
>> 
>> I think we could also add the possibility to choose between compacted, expanded and flattened output form. Maybe also an instance of the (jsonld-java) options object, that allow to control some more details.
>> 
>> When a param is not passed through the (jena) Context mechanism, we use sensible defaults (such as those used today): compacted output, creating a (jsonld-java) context from the defined ns prefixes, and the properties used in the rdf.
>> 
>> One question is: should we have several Symbols defined (one for each of these parameters), or only one, supposed to be of a given class (say “JsonLDWriterParams”). Another one is: what kind of help can be provided to the user to create instances of the objects expected by jsonld-java. And where would go the doc about this?
>> 
>> Something that I do not know about (yet) is framing. Some example (data, @context, frame) to use as a development use case would be helpful
>> 
>> I have some working code. If this makes sense, then I could try to clean it up and make it available. Nothing before 2-3 weeks, however.
>> 
>> BTW Andy, maybe you remember this:
>> https://github.com/jsonld-java/jsonld-java/issues/141
>> "Invalid JSON-LD if Jena defines an "” prefix"
>> you solved the issue by removing “” prefix when creating the context expected by jsonld-java. It looks like instead of removing it, you could replace the “” key by “@vocab” (this is what jsonld-java does somewhere in their code). I tried it and it seems to work correctly. 
>> 
>> Best,
>> 
>> fps
>> 
>> 
>>> Le 10 avr. 2016 à 22:34, Andy Seaborne <an...@apache.org> a écrit :
>>> 
>>> On 10/04/16 15:43, François-Paul Servant wrote:
>>>> Hi,
>>>> 
>>>> beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context.
>>>> 
>>>> If not, any pointer into the code to get me started quickly?
>>>> 
>>>> I’ve read this old thread on this subject:
>>>> http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output
>>>> 
>>>> Best,
>>>> 
>>>> fps
>>>> 
>>>> 
>>> 
>>> Hi,
>>> 
>>> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)
>>> 
>>> Alternatively, JSON-LD framing, any toolkit, applied after output from Jena as mentioned in the thread, is one thing consider especially if what you want is idiomatic JSON for the application domain, that happens to be JSON-LD as well.
>>> 
>>> 	Andy
>>> 
>> 
> 
> 
> 


Re: Controlling JSON-LD output

Posted by Rob Vesse <rv...@dotnetrdf.org>.
Another option to provide a more basic customisation is to simply define several language variants as is done with turtle currently where each variant would be mapped to a JSOn-LD writer with some appropriate default settings.

So for example you might have a compacted variant which would configure the writer to output compact output



On 12/04/2016 09:36, "François-Paul Servant" <fr...@gmail.com> wrote:

>Hi,
>
>> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)
>
>“general, robust and pretty” is probably to hard for me, but I could try something.
>
>I have looked at the code.
>
>Regarding robustness, one difficulty comes from the fact that jsonld-java uses Object as type of most of its arguments in methods
>
>Andy, following your suggestions in the thread already mentioned:
>
>It looks like there is no write methods with the (jena) Context argument in RDFDataMgr, so it would be necessary to add them.
>
>Then there is the question of the stuff that we want to use to control the output by jsonld-java. Andy, you suggested to give the possibility to pass the (jsonld-java) context, and the frame object expected by the framing algo.
>
>I think we could also add the possibility to choose between compacted, expanded and flattened output form. Maybe also an instance of the (jsonld-java) options object, that allow to control some more details.
>
>When a param is not passed through the (jena) Context mechanism, we use sensible defaults (such as those used today): compacted output, creating a (jsonld-java) context from the defined ns prefixes, and the properties used in the rdf.
>
>One question is: should we have several Symbols defined (one for each of these parameters), or only one, supposed to be of a given class (say “JsonLDWriterParams”). Another one is: what kind of help can be provided to the user to create instances of the objects expected by jsonld-java. And where would go the doc about this?
>
>Something that I do not know about (yet) is framing. Some example (data, @context, frame) to use as a development use case would be helpful
>
>I have some working code. If this makes sense, then I could try to clean it up and make it available. Nothing before 2-3 weeks, however.
>
>BTW Andy, maybe you remember this:
>https://github.com/jsonld-java/jsonld-java/issues/141
>"Invalid JSON-LD if Jena defines an "” prefix"
>you solved the issue by removing “” prefix when creating the context expected by jsonld-java. It looks like instead of removing it, you could replace the “” key by “@vocab” (this is what jsonld-java does somewhere in their code). I tried it and it seems to work correctly. 
>
>Best,
>
>fps
>
>
>> Le 10 avr. 2016 à 22:34, Andy Seaborne <an...@apache.org> a écrit :
>> 
>> On 10/04/16 15:43, François-Paul Servant wrote:
>>> Hi,
>>> 
>>> beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context.
>>> 
>>> If not, any pointer into the code to get me started quickly?
>>> 
>>> I’ve read this old thread on this subject:
>>> http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output
>>> 
>>> Best,
>>> 
>>> fps
>>> 
>>> 
>> 
>> Hi,
>> 
>> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)
>> 
>> Alternatively, JSON-LD framing, any toolkit, applied after output from Jena as mentioned in the thread, is one thing consider especially if what you want is idiomatic JSON for the application domain, that happens to be JSON-LD as well.
>> 
>> 	Andy
>> 
>




Re: Controlling JSON-LD output

Posted by François-Paul Servant <fr...@gmail.com>.
Hi,

> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)

“general, robust and pretty” is probably to hard for me, but I could try something.

I have looked at the code.

Regarding robustness, one difficulty comes from the fact that jsonld-java uses Object as type of most of its arguments in methods

Andy, following your suggestions in the thread already mentioned:

It looks like there is no write methods with the (jena) Context argument in RDFDataMgr, so it would be necessary to add them.

Then there is the question of the stuff that we want to use to control the output by jsonld-java. Andy, you suggested to give the possibility to pass the (jsonld-java) context, and the frame object expected by the framing algo.

I think we could also add the possibility to choose between compacted, expanded and flattened output form. Maybe also an instance of the (jsonld-java) options object, that allow to control some more details.

When a param is not passed through the (jena) Context mechanism, we use sensible defaults (such as those used today): compacted output, creating a (jsonld-java) context from the defined ns prefixes, and the properties used in the rdf.

One question is: should we have several Symbols defined (one for each of these parameters), or only one, supposed to be of a given class (say “JsonLDWriterParams”). Another one is: what kind of help can be provided to the user to create instances of the objects expected by jsonld-java. And where would go the doc about this?

Something that I do not know about (yet) is framing. Some example (data, @context, frame) to use as a development use case would be helpful

I have some working code. If this makes sense, then I could try to clean it up and make it available. Nothing before 2-3 weeks, however.

BTW Andy, maybe you remember this:
https://github.com/jsonld-java/jsonld-java/issues/141
"Invalid JSON-LD if Jena defines an "” prefix"
you solved the issue by removing “” prefix when creating the context expected by jsonld-java. It looks like instead of removing it, you could replace the “” key by “@vocab” (this is what jsonld-java does somewhere in their code). I tried it and it seems to work correctly. 

Best,

fps


> Le 10 avr. 2016 à 22:34, Andy Seaborne <an...@apache.org> a écrit :
> 
> On 10/04/16 15:43, François-Paul Servant wrote:
>> Hi,
>> 
>> beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context.
>> 
>> If not, any pointer into the code to get me started quickly?
>> 
>> I’ve read this old thread on this subject:
>> http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output
>> 
>> Best,
>> 
>> fps
>> 
>> 
> 
> Hi,
> 
> There isn't a way to style the output in Jena. It would nice to have something that is general, robust and pretty. (anyone want to have a go?)
> 
> Alternatively, JSON-LD framing, any toolkit, applied after output from Jena as mentioned in the thread, is one thing consider especially if what you want is idiomatic JSON for the application domain, that happens to be JSON-LD as well.
> 
> 	Andy
> 


Re: Controlling JSON-LD output

Posted by Andy Seaborne <an...@apache.org>.
On 10/04/16 15:43, François-Paul Servant wrote:
> Hi,
>
> beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context.
>
> If not, any pointer into the code to get me started quickly?
>
> I’ve read this old thread on this subject:
> http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output
>
> Best,
>
> fps
>
>

Hi,

There isn't a way to style the output in Jena. It would nice to have 
something that is general, robust and pretty. (anyone want to have a go?)

Alternatively, JSON-LD framing, any toolkit, applied after output from 
Jena as mentioned in the thread, is one thing consider especially if 
what you want is idiomatic JSON for the application domain, that happens 
to be JSON-LD as well.

	Andy


Re: Controlling JSON-LD output

Posted by Martynas Jusevičius <ma...@graphity.org>.
As a workaround, you can try XSLT which transforms RDF/XML to JSON-LD:
https://github.com/Graphity/graphity-client/blob/master/src/main/webapp/static/org/graphity/client/xsl/rdfxml2json-ld.xsl

On Sun, Apr 10, 2016 at 4:43 PM, François-Paul Servant
<fr...@gmail.com> wrote:
> Hi,
>
> beside setting the NSPrefixes, are there ways to control the JSON-LD output from Jena? For instance, to choose the format (compact, expanded,…), or to set the context.
>
> If not, any pointer into the code to get me started quickly?
>
> I’ve read this old thread on this subject:
> http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output
>
> Best,
>
> fps
>
>