JSON serialization now even faster and prettier
April 13, 2015
The jsonlite package implements a robust, high performance JSON parser and generator for R, optimized for statistical data and the web. This week version 0.9.16 appeared on CRAN which has a new prettifying system, improved performance and some additional tweaks for the new mongolite package.
Everyones favorite feature of jsonlite: performance. We found a way to significanlty speed up
toJSON for data frames for the cases of
dataframe="rows" (the default) or
dataframe="values". On my macbook I now get these results:
A somewhat larger dataset:
That is pretty darn fast for a text based serialization format. By comparison, we easily beat
write.csv which is actually a much more simple output format:
Pretty even prettier
Yihui has pushed for a new prettifying system that inserts indentation directly in the R code rather than making yajl prettify the entire JSON blob at the end. As a result we can use different indentation rules for different R classes. See the PR for details. The main differce is that atomic vectors are now prettified without linebreaks:
This can be helpful for manually inspecting or debugging your JSON data. The
prettify function still uses yajl, so if you prefer this style, simply use
New mongolite package
There were some additional internal enhancements to support the new mongolite package, which will be announced later this month. This package will extend the concepts and power of jsonlite to the in-database JSON documents. Have a look at the git repository for a sneak preview.