How to return SPARQL results in JSON-LD?

Wouter Beek

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"
        }
      }
    ]
  }
}
Jeen Broekstra

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.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章