cereal_to_json {cereal}R Documentation

Serialize and deserialize the prototype of a data frame to JSON

Description

The function cereal_to_json() serializes the vctrs prototype of a data frame to JSON, and the function cereal_from_json() deserializes from a JSON prototype back to a vctrs prototype.

Usage

cereal_to_json(data)

cereal_from_json(x)

Arguments

data

A data frame

x

A JSON string

Value

cereal_to_json() returns a JSON string like jsonlite::toJSON(), and cereal_from_json() returns a vctrs ptype, like vctrs::vec_ptype().

See Also

cereal_encode(), cereal_decode()

Examples


df <- tibble::tibble(
    a = 1,
    b = 2L,
    c = Sys.Date(),
    d = as.POSIXct("2019-01-01", tz = "America/New_York"),
    e = "x",
    f = factor("blue", levels = c("blue", "green", "red")),
    g = ordered("small", levels = c("small", "medium", "large"))
)

json <- cereal_to_json(df)
json

str(cereal_from_json(json))
## same as:
str(vctrs::vec_ptype(df))


[Package cereal version 0.1.0 Index]