toJSON

0th

Percentile

Stringify R objects to JSON and vice versa

These functions are used to convert R objects into JSON and back. The 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.

Usage
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, ...)

Arguments
x
the object to be encoded
dataframe
how to encode data.frame objects: must be one of "row" or "column"
Date
how to encode Date objects: must be one of "ISO8601" or "epoch"
POSIXt
how to encode POSIXt (datetime) objects: must be one of "string", "ISO8601", "epoch" or "mongo"
factor
how to encode factor objects: must be one of "string" or "integer"
complex
how to encode complex numbers: must be one of "string" or "list"
raw
how to encode raw objects: must be one of "base64", "hex" or "mongo"
digits
max number of digits (after the dot) to print for numeric values
na
how to print NA values. One of "default", "null" or "string"
pretty
adds indentation whitespace to JSON output. See prettify
txt
a string in json format
simplifyVector
automatically coerse JSON arrays containing only scalars into a vector
simplifyDataFrame
automatically coerse JSON arrays containing records (JSON objects with scalars) into a data frame.
simplifyMatrix
automatically coerse JSON arrays with vectors of equal length and mode into a matrix
...
arguments passed on to class specific print methods
Details

The toJSON 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.

Note

All encoded objects should pass the validation at www.jsonlint.org

References

http://www.jsonlint.org

Aliases
  • fromJSON
  • toJSON
Examples
#stringify some data
jsoncars <- toJSON(mtcars, pretty=TRUE)
cat(jsoncars)

#parse it back
fromJSON(jsoncars)
Documentation reproduced from package jsonlite, version 0.9.0, License: Apache License (== 2.0)

Community examples

Looks like there are no examples yet.