Margi
Margi

Reputation: 515

Retrieve Sparql query response in json format

I am using sparql-client from https://github.com/thomasfr/node-sparql-client. I wanted to know if there is a way to retrieve the query results in json format by giving some parameters?

My endpoint is an openrdf-sesame repository.

Currently, my response is as below:

<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
 .....
</sparql>

I used var r = JSON.stringify(results). But r.results show undefined.enter image description here Thanks !

Upvotes: 2

Views: 3088

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85863

Ah, how about this: According to this forum thread

You [have] to query the server directly as in the url below.

http://localhost:8080/openrdf-sesame/repositories/memory?query=SELECT+*+WHERE+{‌​?s+?p+?o}&Accept=application/sparql-results%2Bjson

The SparqlClient constructor looks like it takes two arguments: the endpoint and some options. It looks like you should be able to specify the Accept parameter application/sparql-results+json using that options argument. My ECMAScript is a bit rusty, but I think it'd be something like this:

var endpoint = 'http://example.org/sparql';
var client = new SparqlClient(endpoint, {Accept: 'application/sparql-results+json'});

Upvotes: 5

Related Questions