as_json.Rd
Allows to include raw JS code in JSON object.
as_json(x)
Character storing JS code or object.
A character of class 'json'. The output can be used to store bare JS element withing JSON object.
Along with json_verbatim = TRUE
argument of toJSON
makes passing the code to JSON object possible.
# Function stored as text
jsonlite::toJSON(
list(fun = "function(x) {console.log(x);}"),
auto_unbox = TRUE, json_verbatim = TRUE
)
#> {"fun":"function(x) {console.log(x);}"}
# Function stored as raw JS object
jsonlite::toJSON(
list(fun = as_json("function(x) {console.log(x);}")),
auto_unbox = TRUE, json_verbatim = TRUE
)
#> {"fun":function(x) {console.log(x);}}