toJSON
and
fromJSON
functions use a class based
encoding schema which follows conventions outlines in the
vignette of this package. They implement a consitent and
practical mapping between JSON structures and the
standard data structures in R.fromJSON(txt, simplifyVector = TRUE,
simplifyDataFrame = simplifyVector,
simplifyMatrix = simplifyVector) toJSON(x, dataframe = c("rows", "columns"),
Date = c("ISO8601", "epoch"),
POSIXt = c("string", "ISO8601", "epoch", "mongo"),
factor = c("string", "integer"),
complex = c("string", "list"),
raw = c("base64", "hex", "mongo"),
na = c("default", "null", "string"), digits = 2,
pretty = FALSE, ...)
prettify
print
methodstoJSON
and fromJSON
functions are drop-in replacements for the identically
named functions in packages rjson and RJSONIO. Our
implementation uses an alternative, somewhat more
consistent mapping between R objects and JSON strings.
The serializeJSON
and
unserializeJSON
functions use an
alternative system to convert between R objects and JSON,
which supports more classes but is much more verbose.#stringify some data
jsoncars <- toJSON(mtcars, pretty=TRUE)
cat(jsoncars)
#parse it back
fromJSON(jsoncars)
Run the code above in your browser using DataLab