5

What is a good way to return SPARQL query results in JSON-LD, preferably staying close to the standardized JSON format? Can JSON-LD be returned for every query or only for certain query types?

An example of a SPARQL query result in JSON format (i.e., without JSON-LD enrichment):

{
  "head": {"vars": ["s", "p", "o" ]},
  "results": {
    "bindings": [
      {
        "s": {
          "type":"uri",
          "value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
        },
        "p": {
          "type":"uri",
          "value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
        },
        "o": {
          "type":"uri",
          "value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
        }
      }
    ]
  }
}
Wouter Beek
  • 3,307
  • 16
  • 29
  • Can you clarify what you're after? There are several RDF frameworks with JSON-LD support, all you need to do is specify the syntax format you want for a result, and you'll get it. – Jeen Broekstra Nov 19 '14 at 22:11
  • @JeenBroekstra I want to know whether JSON-LD can be used / has been used for serializing SPARQL query results. For me the difficult part here is not in the tooling but in figuring out what the most optimal mapping is. If such a mapping exists in theory it is trivial to implement it myself. – Wouter Beek Nov 20 '14 at 03:42

1 Answers1

7

JSON-LD is a serialization format for, essentially, RDF graphs, so you can immediately use it for any SPARQL query result that is an RDF graph (that is, the result of any CONSTRUCT or DESCRIBE query).

If you are looking for a format to serialize a variable binding result (that is, the result of a SPARQL SELECT query), you should be using the SPARQL 1.1 Query Results JSON (SPARQL/JSON) format. This is not JSON-LD but it a JSON format specifically designed to serialize SPARQL query results.

Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73