serialise | R Documentation |
Serialise an Object to JSON
serialise(data, ...)
data |
Data to serialise. |
... |
Passed to serialiser. |
Ambiorix uses yyjsonr::write_json_str()
by default for serialization.
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)
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.