[redland-dev] json serialization

Dave Beckett dave at dajobe.org
Wed Jul 12 02:22:14 BST 2006


Eric Hanson wrote:
> Dave Beckett wrote:
>> Eric Hanson wrote:
>>> I noticed Rasql can output in JSON which is really cool!
>>>
>>> Any plans to add JSON as an serialization format from
>>> librdf_serializer_serialize_model_to_string?  Anybody written their own?
>> There's no plans, mostly because of the usual reasons (time) but also that I
>> haven't seen a decent rdf-triples-in-JSON syntax design yet.  The SPARQL
>> results in JSON was an easy translation in comparison.
> 
> Ok, my primary concern at this point is just getting SPARQL results in
> JSON anyway.
> 
> Though I'm having some troubles with that as well.
> 
> Here's the Ruby code I'm trying:
> 
> require 'rdf/redland.rb'
> queryStr = 'select ?s ?p ?o where {?s ?p ?o}'
> store = Redland::HashStore.read_store('wine', '/usr/local/redland-data')
> model = Redland::Model.new(store)
> query = Redland::Query.new(queryStr, 'sparql')
> results = query.execute(model)
> # bad line
> print results.to_string(Redland::Uri.new("json"), nil)


"json" is not the URI you need.
Try http://www.w3.org/2001/sw/DataAccess/json-sparql/
or http://www.mindswap.org/%7Ekendall/sparql-results-json/

Sorry, this doesn't seem to be documented.

> 
> Produces:
> hash-type='bdb',new='no', dir='/usr/local/redland-data',
> write='yes',contexts='yes'
> /usr/local/lib/ruby/1.8/rdf/redland/queryresults.rb:103:in
> `librdf_query_results_to_string': in method
> 'librdf_query_results_to_string', argument 2 of type 'librdf_uri *'
> (TypeError)
>         from /usr/local/lib/ruby/1.8/rdf/redland/queryresults.rb:103:in
> `to_string'
>         from redland.rhtml:10
> 
> 
> The Ruby API function is:
> 
> # File rdf/redland/queryresults.rb, line 91
>     def to_string(format_uri = nil, base_uri = nil)

...

> It says the second argument has a type error, though really the second
> argument on the C API side is the first argument on the Ruby side (cause
> world is wrapped up in the API).  So what's going on here?  I've tried
> various combinations without much luck.

The function above doesn't work.  I've made a patch (& test!) that fixes it.

Dave


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ruby-qr.patch
Type: text/x-patch
Size: 583 bytes
Desc: not available
Url : http://lists.gnomehack.com/pipermail/redland-dev/attachments/20060711/236d5d6c/ruby-qr.bin


More information about the redland-dev mailing list