Result formats


On this page

    By default, Comunica has support for the following result formats:

    Media typeDescription
    application/jsonA custom, simplified JSON result format.
    simpleA custom, text-based result format.
    application/sparql-results+jsonThe SPARQL/JSON results format.
    application/sparql-results+xmlThe SPARQL/XML results format.
    text/csvThe SPARQL/CSV results format.
    text/tab-separated-valuesThe SPARQL/TSV results format.
    statsA custom results format for testing and debugging.
    tableA text-based visual table result format.
    treeA tree-based result format for GraphQL-LD result compacting.
    application/trigThe TriG RDF serialization.
    application/n-quadsThe N-Quads RDF serialization.
    text/turtleThe Turtle RDF serialization.
    application/n-triplesThe N-Triples RDF serialization.
    text/n3The Notation3 serialization.
    application/ld+jsonThe 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.