Convert Remote Sparql Endpoint Json Results Into JSON-LD

- 1 answer

I have a Sparql Endpoint(openrdf sesame) on my local machine. I am able to get the results of the queries(6) in json (using sparql-client node module). Now, I need to convert this json into json-ld so that I can easily display it in the jade file. How can I do this without using rdfstore-js in my node.js application? I did read about jsonld node module. The json data is quite huge and so I cant specify the context for it.

Problem with rdfstore-js: Since the endpoint is on my local machine, I am facing the cross domain issue. So, I tried to load data from remote sparql endpoints into the store but it does not work.

Alternatively, I am open to suggestions wherein I can display data without json-ld.

Edit: After reading Gregg' suggestion, I tried to use CONSTRUCT query. However, the sesame server returns response of the query as text/plain. I tried the content negotiation by giving accept header for json-ld. But it would fail - gives me 'No acceptable file format found'.


I am now using http nodejs module as below. I get the response as text/plain. Is there a way to convert plain text into json-ld ?

var queryString = syllPrefix+" CONSTRUCT { ?uri ?p ?o } where  { ?uri a syll:Person . ?uri ?p ?o}";
var encodedquerystring = encodeURIComponent(queryString);
var options = {
        host: 'localhost',
        port: 8080,
        path: '/openrdf-sesame/repositories/myrepo?query=' +encodedquerystring,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain',

var req = http.get(options, function(res) {
  //  console.log("Got response: " + res.statusCode);
   // console.log('HEADERS: ' + JSON.stringify(res.headers));
    var data = "";
    res.on('data', function (chunk) {
      data += chunk;
    res.on('end', function () {
      console.log (data);
  }).on('error', function(e) {
    console.log("Got error: " + e.message);


Sesame does not support the JSON-LD format out of the box. You will need to install a Sesame-compatible JSON-LD writer library (such as jsonld-java) into your existing Sesame installation.

To do this, get the jsonld-java and jsonld-java-sesame jar files plus their dependencies (unfortunately this is a bit of a chore as you will need to include several third party dependencies, such as Apache libraries and Jackson, as well - but you can download everything from Maven Central) and drop them into your Sesame deployment directory inside Tomcat. Typically this directory should be something like [TOMCAT_DIR]/webapps/openrdf-sesame/WEB-INF/lib. Once you've done this, you'll need to restart Tomcat for Sesame to recognize the new writer.

Once this is done, supplying the correct Accept header (media type application/ld+json) should get you JSON-LD results on your graph queries.

Alternatively, you can try using the RDF 1.1 JSON Alternate Serialization format, which is not really a standard like JSON-LD is, but is supported by Sesame. Media type application/rdf+json.