Thanks Andy. qexec.setSelectContentType is what i was looking for.

Best Regards,
Roshan





> On 29 Jul 2015, at 09:56, Andy Seaborne <a...@apache.org> wrote:
> 
> On 28/07/15 23:20, Roshan Bharath Das wrote:
>> Thanks.
>> But I would like to know if there is an option to encode in the URL so that
>> I don't have to convert after receiving the data. Because fuseki server can
>> give the output data in xml, text, json, csv form.
> 
> Not the URL - it's done with content negotiation (many systems including 
> Fuseki do allow something like ?output= but it's not in the standard)
> 
>    QueryEngineHTTP qexec =
>      (QueryEngineHTTP) QueryExecutionFactory.sparqlService(uri, query);
>    // request JSON results
>    qexec.setSelectContentType(WebContent.contentTypeResultsJSON);
>    ResultSet results = qexec.execSelect();
> 
> >>> Query query = QueryFactory.create(queryString);
> >>> QueryExecution qe = QueryExecutionFactory.sparqlService(linkedmdb,query);
> >>> ResultSet result = qe.execSelect();
> >>> The result is in XML format and I want it to be in JSON format.
> 
> Not exactly - the printing of the ResultSet object is in XML but that is 
> different from what the server produced which might be XML, JSON, TSV. It is 
> parsed on receipt to an internal form then be formatted for output.  The 
> parsing and conversion is not expensive and will stream if possible.
> 
> So as Martynas says, ResultSetFormatter.outputAsJSON()
> 
> If you don't want the conversion not internal java ResultSet,
> you just make a call direct with HTTP GET and read the input stream.
> 
> Jena's packaging up of common uses (for jena) of HTTP is in HttpOps.
> 
>       Andy
> 
>> 
>> Best Regards,
>> Roshan
>>  On Jul 28, 2015 10:03 PM, "Martynas Jusevičius" <marty...@graphity.org>
>> wrote:
>> 
>>> Roshan,
>>> 
>>> try ResultSetFormatter.outputAsJSON()
>>> 
>>> https://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/ResultSetFormatter.html#outputAsJSON(com.hp.hpl.jena.query.ResultSet)
>>> 
>>> On Tue, Jul 28, 2015 at 9:18 PM, Roshan Bharath Das
>>> <roshanbharath...@gmail.com> wrote:
>>>> Hello,
>>>> 
>>>> How can I decide to get the query result format for a sparqlService in
>>> JSON for example?.
>>>> 
>>>> Below is my code:
>>>> Query query = QueryFactory.create(queryString);
>>>> QueryExecution qe = QueryExecutionFactory.sparqlService(linkedmdb,query);
>>>> ResultSet result = qe.execSelect();
>>>> The result is in XML format and I want it to be in JSON format.
>>>> 
>>>> Best Regards,
>>>> Roshan
>>>> 
>>>> 
>>> 
>> 
> 

Reply via email to