- From: Ivan Herman <ivan@w3.org>
- Date: Fri, 2 Sep 2011 09:23:19 +0200
- To: Linked JSON <public-linked-json@w3.org>
- Cc: Danny Ayers <danny.ayers@gmail.com>
Just for those who read this but would not be familiar with SPARQL: the document Danny refers to defines the return format for ordinary SPARQL queries, _not_ CONSTRUCT queries. The difference is that CONSTRUCT queries return, formally, an RDF graph, ordinary queries return variable bindings. Ie, formally, if some sort of J-Triples were around, there is no problem for a SPARQL processor to adopt that for the CONSTRUCT case, while still using the current JSON return format for variable binding data... (Sorry Danny, this does not invalidate what you write, but we should be careful not to give the wrong impression...:-) Ivan On Sep 2, 2011, at 24:22 , Danny Ayers wrote: > Ivan was talking earlier about the potential for a "J-Triples" syntax, > a JSON version of NTriples. > > There's a W3C Working Group Note on Serializing SPARQL Query Results > in JSON [1]. The serialization is a fairly direct translation of the > XML results format into JSON. It's very easy to derive a practical > J-Triples format from it. > > If we run the query: > > SELECT ?s ?p ?o WHERE { ?s ?p ?o } > > over an arbitrary graph, we get something like: > > { > "head": { > "vars": [ "s" , "p" , "o" ] > } , > "results": { > > "bindings": [ > { > "s": { "type": "uri" , "value": "http://hyperdata.org/seki/Hello" } , > "p": { "type": "uri" , "value": > "http://purl.org/dc/elements/1.1/date" } , > "o": { "type": "literal" , "value": "2011-08-30T19:00Z" } > } , > { > "s": { "type": "uri" , "value": "http://hyperdata.org/seki/Hello" } , > "p": { "type": "uri" , "value": "http://xmlns.com/foaf/0.1/maker" } , > "o": { "type": "uri" , "value": "http://dannyayers.com/me#" } > } , > ... > > If we stick such a result set into a JSON/Javascript object - > > var sr = // results // > > it's possible to access the values through paths like - > > sr.results.bindings[0].o.value > > which in the above is "2011-08-30T19:00Z" > > but there's stuff here that's redundant, so let: > > var jt = sr.results.bindings; > > effectively making jt an array of triples, so now, e.g.: > > jt[0].o.value == "2011-08-30T19:00Z" > jt[0].o.type == "literal" > > There's still a bit of redundancy because : > > s.type can only be "uri" | "bnode" > p.type can only be "uri" > though o.type can be "uri" | "bnode" | "literal" > > but if you wanted to serialize without using SPARQL, you could just > leave the redundant pairs out. > > There's also xml:lang and xsd typed literals to consider, but again > those are effectively already spec'd out in SPARQL results, e.g. : > > "o": { "type": "literal" , "value": "2011-08-30T19:00Z", > "datatype": "http://www.w3.org/2001/XMLSchema#integer"} > > "o": { "type": "literal" , "value": "hello", "xml:lang":"en" } > > The only question for which there wasn't already an answer was whether > to use "s" or "subject" for the node labels. I've chosen the shorter > form here on the basis that it's fewer bits and anyone using a format > like this will recognize the s, p, o pattern. > > Thoughts? > > Cheers, > Danny. > > [1] http://www.w3.org/TR/rdf-sparql-json-res/ > > > -- > http://dannyayers.com > ---- Ivan Herman, W3C Semantic Web Activity Lead Home: http://www.w3.org/People/Ivan/ mobile: +31-641044153 PGP Key: http://www.ivan-herman.net/pgpkey.html FOAF: http://www.ivan-herman.net/foaf.rdf
Received on Friday, 2 September 2011 07:23:32 UTC