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 \
        "SELECT * WHERE { ?s ?p ?o } LIMIT 100" \
        -t "application/sparql-results+json"
    {"head": {"vars":["s","p","o"]},
    "results": { "bindings": [
    {"s":{"value":"","type":"uri"},"p":{"value":"","type":"uri"},"o":{"value":"Biloxi Daily Herald","type":"literal"}},
    {"s":{"value":"","type":"uri"},"p":{"value":"","type":"uri"},"o":{"value":"A New System of Weights and Measures","type":"literal"}},
    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 <>.
        ?s ?p ?o
      } LIMIT 100`, {
      sources: [''],
    const { data } = await myEngine.resultToString(result,
    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.