
Last chance! 50% off unlimited learning
Sale ends in
Convert a JSON object into an R object.
fromJSON( json_str, file, method = "C", unexpected.escape = "error", simplify = TRUE )
a JSON object to convert
the name of a file to read the json_str from; this can also be a URL. Only one of json_str or file must be supplied.
use the C
implementation, or the older slower (and one day to be depricated) R
implementation
changed handling of unexpected escaped characters. Handling value should be one of "error", "skip", or "keep"; on unexpected characters issue an error
, skip
the character, or keep
the character
If TRUE, attempt to convert json-encoded lists into vectors where appropriate. If FALSE, all json-encoded lists will be wrapped in a list even if they are all of the same data type.
R object that corresponds to the JSON object
# NOT RUN {
fromJSON('[1,2,3]', simplify=TRUE)
# returns c(1,2,3)
fromJSON('[1,2,3]', simplify=FALSE)
# returns list(1,2,3)
#As a result, this will output "1"
toJSON(fromJSON('[1]', simplify=TRUE))
#Compared with this which will output "[1]" as expected
toJSON(fromJSON('[1]', simplify=TRUE))
#R vs C execution time
x <- toJSON( iris )
system.time( y <- fromJSON(x) )
system.time( y2 <- fromJSON(x,method = "R") )
# }
Run the code above in your browser using DataLab