Result formats
On this page
By default, Comunica has support for the following result formats:
Media type | Description |
---|---|
application/json | A custom, simplified JSON result format. |
simple | A custom, text-based result format. |
application/sparql-results+json | The SPARQL/JSON results format. |
application/sparql-results+xml | The SPARQL/XML results format. |
text/csv | The SPARQL/CSV results format. |
text/tab-separated-values | The SPARQL/TSV results format. |
stats | A custom results format for testing and debugging. |
table | A text-based visual table result format. |
tree | A tree-based result format for GraphQL-LD result compacting. |
application/trig | The TriG RDF serialization. |
application/n-quads | The N-Quads RDF serialization. |
text/turtle | The Turtle RDF serialization. |
application/n-triples | The N-Triples RDF serialization. |
text/n3 | The Notation3 serialization. |
application/ld+json | The JSON-LD RDF serialization. |
Querying from the command line
When using Comunica from the command line,
the result format can be set using the -t
option:
$ comunica-sparql https://fragments.dbpedia.org/2016-04/en \ "SELECT * WHERE { ?s ?p ?o } LIMIT 100" \ -t "application/sparql-results+json"
{"head": {"vars":["s","p","o"]}, "results": { "bindings": [ {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/date","type":"uri"},"o":{"value":"1899-05-06","type":"literal","datatype":"http://www.w3.org/2001/XMLSchema#date"}}, {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/isCitedBy","type":"uri"},"o":{"value":"http://dbpedia.org/resource/Tierce_(unit)","type":"uri"}}, {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/newspaper","type":"uri"},"o":{"value":"Biloxi Daily Herald","type":"literal"}}, {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/page","type":"uri"},"o":{"value":"6","type":"literal"}}, {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/title","type":"uri"},"o":{"value":"A New System of Weights and Measures","type":"literal"}}, {"s":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"},"p":{"value":"http://dbpedia.org/property/url","type":"uri"},"o":{"value":"http://0-access.newspaperarchive.com.lib.utep.edu/us/mississippi/biloxi/biloxi-daily-herald/1899/05-06/page-6?tag=tierce+wine&rtserp=tags/tierce-wine?page=2","type":"uri"}}, ...
All available formats can be printed via
comunica-sparql --listformats
Querying in a JavaScript app
When using Comunica in a JavaScript application,
results can be serialized to a certain format using resultToString()
:
const result = await myEngine.query(` SELECT ?s ?p ?o WHERE { ?s ?p <http://dbpedia.org/resource/Belgium>. ?s ?p ?o } LIMIT 100`, { sources: ['http://fragments.dbpedia.org/2015/en'], }); const { data } = await myEngine.resultToString(result, 'application/sparql-results+json'); data.pipe(process.stdout); // Print to standard output
The resultToString()
method accepts a query result and a result format media type.
The media type is optional, and will default to application/json
for bindings, application/trig
for quads, and simple
for booleans.
All available result formats can be retrieved programmatically
by invoking the asynchronous
getResultMediaTypes()
method.