serialise: Serialise an Object to JSON

View source: R/serialise.R

serialiseR Documentation

Serialise an Object to JSON

Description

Serialise an Object to JSON

Usage

serialise(data, ...)

Arguments

data

Data to serialise.

...

Passed to serialiser.

Details

Ambiorix uses yyjsonr::write_json_str() by default for serialization.

Custom Serialiser

To override the default, set the AMBIORIX_SERIALISER option to a function that accepts:

  • data: Object to serialise.

  • ...: Additional arguments passed to the function.

For example:

my_serialiser <- function(data, ...) {
 jsonlite::toJSON(x = data, ...)
}

options(AMBIORIX_SERIALISER = my_serialiser)

Examples

if (interactive()) {
  # a list:
  response <- list(code = 200L, msg = "hello, world!")

  serialise(response)
  #> {"code":200,"msg":"hello, world"}

  serialise(response, auto_unbox = FALSE)
  #> {"code":[200],"msg":["hello, world"]}

  # data.frame:
  serialise(cars)
}


JohnCoene/ambiorix documentation built on March 5, 2025, 5:35 a.m.