serialise {ambiorix} | R 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)
Value
JSON string.
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)
}
[Package ambiorix version 2.2.0 Index]