# Snarl connection: how to change query result format

**URL:** <https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037>\
**Category:** Support\
**Created:** [October 21, 2022, 1:31pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037 "2022-10-21T13:31:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cesar](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@Cesar](https://community.stardog.com/u/Cesar)\
**Post date:** [October 21, 2022, 1:31pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/1 "2022-10-21T13:31:59Z")

</div>

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

```auto
snarlTemplate.execute(
        connection -> { SelectQuery query =
                connection.select(sparql).dataset(dataset);
//rest of My things here}
)

```

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

```auto
((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.

```nohighlight

```

Thank you.

---

<div class="post-metadata">

**Author:** ![Cesar](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@Cesar](https://community.stardog.com/u/Cesar)\
**Post date:** [October 24, 2022, 12:02am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/2 "2022-10-24T00:02:49Z")

</div>

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

```auto
public static final QueryResultFormat JSON = new QueryResultFormatImpl("SPARQL/JSON", Values.iri("http://www.w3.org/ns/formats/SPARQL_Results_JSON"), ImmutableList.of("application/sparql-results+json", "application/json"), ImmutableList.of("srj", "json"));

```

I've found an example here: [stardog-examples/ExampleService.java at 6c3afd3d33b4c267349898c549d1fdc1e5bf2884 · stardog-union/stardog-examples · GitHub](https://github.com/stardog-union/stardog-examples/blob/6c3afd3d33b4c267349898c549d1fdc1e5bf2884/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java)

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

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [November 3, 2022, 12:44pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/3 "2022-11-03T12:44:44Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [November 23, 2022, 1:55am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/4 "2022-11-23T01:55:25Z")

</div>

Automatically bumped on November 23, 2022, 1:55am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 16, 2022, 11:00am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/5 "2022-12-16T11:00:38Z")

</div>

Automatically bumped on December 16, 2022, 11:00am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [January 12, 2023, 4:55am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/6 "2023-01-12T04:55:33Z")

</div>

Automatically bumped on January 12, 2023, 4:55am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 8, 2023, 3:24pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/7 "2023-02-08T15:24:53Z")

</div>

Automatically bumped on February 8, 2023, 3:24pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [March 9, 2023, 2:40am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/8 "2023-03-09T02:40:37Z")

</div>

Automatically bumped on March 9, 2023, 2:40am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [April 6, 2023, 1:49pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/9 "2023-04-06T13:49:57Z")

</div>

Automatically bumped on April 6, 2023, 1:49pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [May 7, 2023, 1:02am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/10 "2023-05-07T01:02:14Z")

</div>

Automatically bumped on May 7, 2023, 1:02am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 6, 2023, 8:09pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/11 "2023-06-06T20:09:26Z")

</div>

Automatically bumped on June 6, 2023, 8:09pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [July 9, 2023, 4:26pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/12 "2023-07-09T16:26:48Z")

</div>

Automatically bumped on July 9, 2023, 4:26pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 13, 2023, 6:08am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/13 "2023-08-13T06:08:57Z")

</div>

Automatically bumped on August 13, 2023, 6:08am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 22, 2023, 1:13pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/14 "2023-09-22T13:13:23Z")

</div>

Automatically bumped on September 22, 2023, 1:13pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [November 6, 2023, 10:37pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/15 "2023-11-06T22:37:00Z")

</div>

Automatically bumped on November 6, 2023, 10:37pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 25, 2023, 3:54pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/16 "2023-12-25T15:54:26Z")

</div>

Automatically bumped on December 25, 2023, 3:54pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 17, 2024, 12:26pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/17 "2024-02-17T12:26:34Z")

</div>

Automatically bumped on February 17, 2024, 12:26pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [April 15, 2024, 9:16am UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/18 "2024-04-15T09:16:33Z")

</div>

Automatically bumped on April 15, 2024, 9:16am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 9, 2024, 3:49pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/19 "2024-08-09T15:49:20Z")

</div>

Automatically bumped on August 9, 2024, 3:49pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 15, 2025, 1:20pm UTC](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037/20 "2025-02-15T13:20:00Z")

</div>

Automatically bumped on February 15, 2025, 1:20pm UTC



[Next page](https://community.stardog.com/t/snarl-connection-how-to-change-query-result-format/4037.md?page=2)
