<docbook><section><title>VirtTipsAndTricksGuideSPARQLEndpointQueryResultOutput</title><title>How to output the results of a SPARQL query run against the /sparql endpoint to a file in Virtuoso?</title>How to output the results of a SPARQL query run against the /sparql endpoint to a file in Virtuoso?
<bridgehead class="http://www.w3.org/1999/xhtml:h2">Why?</bridgehead>
 To manage output results of a SPARQL query.<bridgehead class="http://www.w3.org/1999/xhtml:h2">What?</bridgehead>
 Save the output results of a SPARQL query that is executed against Virtuoso SPARQL Endpoint using <emphasis>curl</emphasis> command.<bridgehead class="http://www.w3.org/1999/xhtml:h2">How?</bridgehead>
<para>To save the output of a SPARQL query against the Virtuoso /sparql endpoint to a file, a <emphasis>curl</emphasis> command of the following form can be run:</para>
<programlisting>curl --request POST &#39;http://hostname:portno/sparql/?&#39; --header &#39;Accept-Encoding: gzip&#39; 
--data &#39;format=outputformat&#39; --data-urlencode &#39;query=SPARQLQuery&#39; --output &#39;filename.gz&#39;
</programlisting><para> The <ulink url="http://docs.openlinksw.com/virtuoso/rdfsparqlprotocolendpoint/#rdfsupportedmimesofprotocolserver">supported &quot;<emphasis>outputformat</emphasis>&quot; values</ulink>, are detailed in the <ulink url="http://docs.openlinksw.com/virtuoso/rdfsparqlprotocolendpoint/#rdfrequestparamsextensions">SPARQL Protocol Extensions</ulink> section of the Virtuoso documentation.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Usage Example</bridgehead>
<para>The following example demonstrates how to save the output of a simple CONSTRUCT Query that returns the first 5 triples from the Quad store in <emphasis>JSON</emphasis> format:</para>
<programlisting>$ curl --request POST &#39;http://localhost:8890/sparql/?&#39; --header &#39;Accept-Encoding: gzip&#39; --data &#39;format=json&#39; --data-urlencode &#39;query=CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }LIMIT 5&#39; --output &#39;filename.gz&#39;

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   398    0   288  100   110  41854  15986 --:--:-- --:--:-- --:--:-- 48000
$ gzip -cd filename.gz | more

{ &quot;head&quot;: { &quot;link&quot;: [], &quot;vars&quot;: [ &quot;s&quot;, &quot;p&quot;, &quot;o&quot; ] },
  &quot;results&quot;: { &quot;distinct&quot;: false, &quot;ordered&quot;: true, &quot;bindings&quot;: [
    { &quot;s&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }      , &quot;p&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }  , &quot;o&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#Property&quot; }},
    { &quot;s&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/virtrdf-data-formats#default-iid-nullable&quot; }  , &quot;p&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }  , &quot;o&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat&quot; }},
    { &quot;s&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/virtrdf-data-formats#default-iid&quot; }   , &quot;p&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }  , &quot;o&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat&quot; }},
    { &quot;s&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/virtrdf-data-formats#default-iid-nonblank-nullable&quot; } , &quot;p&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }  , &quot;o&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat&quot; }},
    { &quot;s&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/virtrdf-data-formats#default-iid-nonblank&quot; }  , &quot;p&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&quot; }  , &quot;o&quot;: { &quot;type&quot; : &quot;uri&quot;, &quot;value&quot; : &quot;http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat&quot; }} ] } }
$ 
</programlisting><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="VirtTipsAndTricksGuideISQLQueryResultOutput">How to output from iSQL the result of a SQL SELECT query to a file in Virtuoso?</ulink> </listitem>
<listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink> </listitem>
</itemizedlist></section></docbook>