问题
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