Save or load R object in 'JSON' format
Examples
# Serialize
save_json(list(a = 1, b = function(){}))
#> {
#> "type": "list",
#> "attributes": {
#> "names": {
#> "type": "character",
#> "attributes": {},
#> "value": ["a", "b"]
#> }
#> },
#> "value": [
#> {
#> "type": "double",
#> "attributes": {},
#> "value": [1]
#> },
#> {
#> "type": "closure",
#> "attributes": {},
#> "value": [
#> {
#> "type": "language",
#> "attributes": {},
#> "value": ["{", "}"]
#> }
#> ]
#> }
#> ]
#> }
# use toJSON
save_json(list(a = 1, b = function(){}), serialize = FALSE)
#> {
#> "a": [1],
#> "b": ["function () ", "{", "}"]
#> }
# Demo of using serializer
f1 <- tempfile(fileext = ".json")
save_json(x ~ y + 1, f1)
load_json(f1)
#> x ~ y + 1
#> <environment: 0x12ff5bbd8>
unlink(f1)