January 4, 2017 From rOpenSci (https://ropensci.org/blog/2017/01/04/jsonlite-12/). Except where otherwise noted, content on this site is licensed under the CC-BY license.
write_jsonconvenience wrappers, #161
modp_numtoafrom upstream, fixes a rounding issue in #148.
asJSON.POSIXtdoes not use sci notation for negative values, #155
num_to_charto properly print large negative numbers
Use the Github compare page to see the full diff on metacran.
The package has gained new high level functions
write_json. These are wrappers for
toJSON which read/write json directly from/to disk. This API is consistent with tidyverse packages like readr, readxl and haven (see #161).
The only thing to note is that
read_json does not simplify by default, as is done by
fromJSON. For example:
# Write Data frame to a temp file tmp <- tempfile() write_json(iris, tmp) # Nested lists read_json(tmp) # A data frame read_json(tmp, simplifyVector = TRUE)
read_json only returns a data frame when
simplifyVector is explicitly set to
We have ported a bit of C code to optimize simplification for data frame structures. This script compares performance for both versions:
# example json json <- jsonlite::toJSON(ggplot2::diamonds) # Test with jsonlite 1.1 devtools::install_github("cran/[email protected]") microbenchmark::microbenchmark(jsonlite::fromJSON(json), times = 50) # Unload jsonlite 1.1 (might need restart R on windows) unloadNamespace("jsonlite") library.dynam.unload('jsonlite', find.package('jsonlite')) # Test with jsonlite 1.2 devtools::install_github("cran/[email protected]") microbenchmark::microbenchmark(jsonlite::fromJSON(json), times = 50)
On my Macbook this has reduced the median time from approx 0.91s to 0.76s.