Serializers are used in Plumber to transform the R object produced by a filter/endpoint into an HTTP response that can be returned to the client. See here for more details on Plumber serializers and how to customize their behavior.

serializer_headers(headers = list(), serialize_fn = identity)

serializer_content_type(type, serialize_fn = identity)

serializer_csv(..., type = "text/csv; charset=UTF-8")

serializer_tsv(..., type = "text/tab-separated-values; charset=UTF-8")

serializer_html(type = "text/html; charset=UTF-8")

serializer_json(..., type = "application/json")

serializer_unboxed_json(auto_unbox = TRUE, ..., type = "application/json")

serializer_rds(version = "2", ascii = FALSE, ..., type = "application/rds")

serializer_feather(type = "application/feather")

serializer_yaml(..., type = "text/x-yaml; charset=UTF-8")

  serialize_fn = as.character,
  type = "text/plain; charset=UTF-8"

serializer_format(..., type = "text/plain; charset=UTF-8")

serializer_print(..., type = "text/plain; charset=UTF-8")

serializer_cat(..., type = "text/plain; charset=UTF-8")

serializer_write_file(type, write_fn, fileext = NULL)

serializer_htmlwidget(..., type = "text/html; charset=UTF-8")

serializer_device(type, dev_on, dev_off =

serializer_jpeg(..., type = "image/jpeg")

serializer_png(..., type = "image/png")

serializer_svg(..., type = "image/svg+xml")

serializer_bmp(..., type = "image/bmp")

serializer_tiff(..., type = "image/tiff")

serializer_pdf(..., type = "application/pdf")



list() of headers to add to the response object


Function to serialize the data. The result object will be converted to a character string. Ex: jsonlite::toJSON().


The value to provide for the Content-Type HTTP header.


extra arguments supplied to respective internal serialization function.


automatically unbox all atomic vectors of length 1. It is usually safer to avoid this and instead use the unbox function to unbox individual elements. An exception is that objects of class AsIs (i.e. wrapped in I()) are not automatically unboxed. This is a way to mark single values as length-1 arrays.


the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.


a logical. If TRUE or NA, an ASCII representation is written; otherwise (default) a binary one. See also the comments in the help for save.


Function that should write serialized content to the temp file provided. write_fn should have the function signature of function(value, tmp_file){}.


A non-empty character vector giving the file extension. This value will try to be inferred from the content type provided.


Function to turn on a graphics device. The graphics device dev_on function will receive any arguments supplied to the serializer in addition to filename. filename points to the temporary file name that should be used when saving content.


Function to turn off the graphics device. Defaults to


  • serializer_headers: Add a static list of headers to each return value. Will add Content-Disposition header if a value is the result of as_attachment().

  • serializer_content_type: Adds a Content-Type header to the response object

  • serializer_csv: CSV serializer. See also: readr::format_csv()

  • serializer_tsv: TSV serializer. See also: readr::format_tsv()

  • serializer_html: HTML serializer

  • serializer_json: JSON serializer. See also: jsonlite::toJSON()

  • serializer_unboxed_json: JSON serializer with auto_unbox defaulting to TRUE. See also: jsonlite::toJSON()

  • serializer_rds: RDS serializer. See also: base::serialize()

  • serializer_feather: feather serializer. See also: feather::write_feather()

  • serializer_yaml: YAML serializer. See also: yaml::as.yaml()

  • serializer_text: Text serializer. See also: as.character()

  • serializer_format: Text serializer. See also: format()

  • serializer_print: Text serializer. Captures the output of print()

  • serializer_cat: Text serializer. Captures the output of cat()

  • serializer_write_file: Write output to a temp file whose contents are read back as a serialized response. serializer_write_file() creates (and cleans up) a temp file, calls the serializer (which should write to the temp file), and then reads the contents back as the serialized value. If the content type starts with "text", the return result will be read into a character string, otherwise the result will be returned as a raw vector.

  • serializer_htmlwidget: htmlwidget serializer. See also: htmlwidgets::saveWidget()

  • serializer_device: Helper method to create graphics device serializers, such as serializer_png(). See also: endpoint_serializer()

  • serializer_jpeg: JPEG image serializer. See also: grDevices::jpeg()

  • serializer_png: PNG image serializer. See also: grDevices::png()

  • serializer_svg: SVG image serializer. See also: grDevices::svg()

  • serializer_bmp: BMP image serializer. See also: grDevices::bmp()

  • serializer_tiff: TIFF image serializer. See also: grDevices::tiff()

  • serializer_pdf: PDF image serializer. See also: grDevices::pdf()