W3C home > Mailing lists > Public > public-linked-json@w3.org > September 2011

RE: Practical J-Triples from SPARQL JSON results

From: Markus Lanthaler <markus.lanthaler@gmx.net>
Date: Fri, 2 Sep 2011 00:52:16 +0200
To: "'Linked JSON'" <public-linked-json@w3.org>
Message-ID: <000f01cc68f9$cc853890$658fa9b0$@lanthaler@gmx.net>
In JSON-LD you could serialize this as:

[
    {
        "@subject": "http://hyperdata.org/seki/Hello",
        "http://purl.org/dc/elements/1.1/date": "2011-08-30T19:00Z"
    },
    {
        "@subject": "http://hyperdata.org/seki/Hello",
        "http://xmlns.com/foaf/0.1/maker": {
            "@iri": "http://dannyayers.com/me#"
        }
    }
]




> -----Original Message-----
> From: public-linked-json-request@w3.org [mailto:public-linked-json-
> request@w3.org] On Behalf Of Danny Ayers
> Sent: Friday, September 02, 2011 12:22 AM
> To: public-linked-json@w3.org
> Cc: Ivan Herman
> Subject: Practical J-Triples from SPARQL JSON results
> 
> 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



--
Markus Lanthaler
@markuslanthaler
Received on Thursday, 1 September 2011 22:52:58 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:18:32 UTC