Thanks for your clear answer. You're right, JSON-LD is probably what I'm looking for. I'm using the latest Fuseki snapshot (feb 24) but I don't find a way to export DATA in JSON-LD format. Is it supported by Fuseki yet, or only Jena?
---------- Forwarded message ---------- From: Rob Vesse <[email protected]> Date: 2014-03-04 14:55 GMT+01:00 Subject: Re: Unexpected response from Fuseki when asking for JSON To: [email protected] The JSON output follows the unofficial RDF/JSON specification from http://docs.api.talis.com/platform-api/output-types/rdf-json It does not convey any tree structure rather it simply acts as a list of triples grouped by subjects. That your graph happens to have a tree like structure and that the other formats you've shown (Turtle and RDF/XML) happen to convey it is coincidental. You should not rely on the structure of the returned data for anything because both those formats could equally serialise the same data in an earlier non-tree like way. Recent development snapshots have support for JSON-LD (http://www.w3.org/TR/json-ld/) which may be of interest to you which is designed to be more like normal JSON it its structure. Btw the extra ex:item in the ex:subitems list is there because you CONSTRUCTed a graph that contains it, it is not "extra" it is what your query asked for! And the RDF/XML output quite clearly contains this as well though I appreciate RDF/XML is somewhat awkward to read if you aren't used to it. Rob On 04/03/2014 12:52, "Julien Nauroy" <[email protected]> wrote: >Dear all, > >I'm trying to export the result of a CONSTRUCT in JSON format, but the >output seems unexpected. I'm using Fuseki 1.0.2 >I've come up with a simple example to try and explain my problem. > >Here's the test set: > >CREATE GRAPH <http://test/> > >PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> >PREFIX ex: <http://example.org/> >INSERT DATA { GRAPH <http://test/> { ><ex:i1> > ex:items [ > ex:item "item 1"; > ex:item "item 2"; > ex:subitems [ >ex:item "subitem 1"; >ex:item "subitem 2"; > ] >]. >} } > > >Here's the CONSTRUCT query : > >PREFIX ex: <http://example.org/> >CONSTRUCT { >?i ex:items ?items. >?items ex:item ?item. > ?items ex:subitems ?subitems. >?subitems ex:item ?subitem. >} WHERE { >GRAPH <http://test/> { > ?i ex:items ?items. >?items ex:item ?item. >OPTIONAL { >?items ex:subitems ?subitems. > ?subitems ex:item ?subitem. >} >} >} > > >When running it in Fuseki's web interface and asking for plain text, >here's >the answer: ><ex:i1> ex:items [ ex:item "item 1" , "item 2" ; > ex:subitems [ ex:item "subitem 1" , "subitem 2" ] > ] . > >The response looks fine to me, except the extra "ex:item" in the list of >subitems but since it's a made up example, I didn't take time to >investigate (maybe it's a bu, since the XML output doesnt include this >item?). > >I've also tried to ask for XML as an oututput and the result correspond, >except the extra ex:item is not present: > <rdf:Description rdf:about="ex:i1"> > <ex:items rdf:parseType="Resource"> > <ex:item>item 1</ex:item> > <ex:subitems rdf:parseType="Resource"> > <ex:item>subitem 1</ex:item> > <ex:item>subitem 2</ex:item> > </ex:subitems> > <ex:item>item 2</ex:item> > </ex:items> > </rdf:Description> > > >Now, when asking for JSON, the result is not structured the same way: >instead of receiving a tree-like structure such as the previous one, the >subitems are in separate entities instead of being nested. Plus, the names >of the blank nodes, often called "b0" "b1" and so on, have funny names. >The >output is below, since it takes a lot of space. > >Is the result I get the intended output? Can I do something to have nested >structures that look like the the XML ouput? > > >Best regards, >Julien Nauroy > > > >JSON output: >{ > "_:-6abd5fb1:144791bd785:fcc" : { > "http://example.org/item" : [ { > "type" : "literal" , > "value" : "item 1" > } > , { > "type" : "literal" , > "value" : "item 2" > } > ] , > "http://example.org/subitems" : [ { > "type" : "bnode" , > "value" : "_:-6abd5fb1:144791bd785:fcd" > } > ] > } > , > "ex:i1" : { > "http://example.org/items" : [ { > "type" : "bnode" , > "value" : "_:-6abd5fb1:144791bd785:fcc" > } > ] > } > , > "_:-6abd5fb1:144791bd785:fcd" : { > "http://example.org/item" : [ { > "type" : "literal" , > "value" : "subitem 1" > } > , { > "type" : "literal" , > "value" : "subitem 2" > } > ] > } >}
