Snarl connection: how to change query result format

This pseudo-code shows how I usually use snarl to execute my queries.

        connection -> { SelectQuery query =
//rest of My things here}

During the runtime, I can see that under the object query here:

((QueryResultFormatImpl) ((HttpClientImpl) ((HttpConnection) ((SelectQueryImpl) query).mConn).mClient).mDefaultQueryResultFormat).mName

There is a DefaultQueryResultFormat that is set to BINARY. I'm interested to get the result in another formats. I have a question: how can we change it to JSON?

I saw something like this, but I do not know how it applies.

Thank you.

I'm interested to change the query result to something like this:

public static final QueryResultFormat JSON = new QueryResultFormatImpl("SPARQL/JSON", Values.iri(""), ImmutableList.of("application/sparql-results+json", "application/json"), ImmutableList.of("srj", "json"));

I've found an example here: stardog-examples/ at 6c3afd3d33b4c267349898c549d1fdc1e5bf2884 · stardog-union/stardog-examples · GitHub

I am not sure if I can change the QueryResultFormat without using queryResultParser.
Thank you.

Hi Cesar,

We offer a number of utility/static classes/methods for query and result i/o. In this case you can use QueryResultWriters to get what you want:

snarlTemplate.<Void>execute(connection -> {
			try (SelectQueryResult result = {
				QueryResultWriters.write(result, Paths.get("/var/opt/stardog/out.json"), QueryResultFormats.JSON);
			catch (IOException theE) {
			return null;