How to return SPARQL results in JSON-LD?

喜你入骨 提交于 2019-12-07 14:39:21

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/27022690/how-to-return-sparql-results-in-json-ld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!