New features in jsonlite 0.9.14
December 5, 2014
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.14 appeared on CRAN which adds some handy new features.
Significant Digits
By default, the digits
argument in toJSON
specifies the number of decimal digits to print:
A feature requested by Winston Chang was to control precision of number formatting. You can now specify the number of significant digits, analogous to the signif
function in base R. Either set signif = TRUE
or specify the digits
argument using I()
:
Prettify Indent
A feature requested by Yihui Xie was to control the number of spaces to indent prettified json. The default is still 4 spaces:
The number of indent spaces can be changed by setting the pretty
argument to an integer. For example to indent by only 2 spaces:
Support for 64bit integers in toJSON
Another new feature is support for 64bit integers from the bit64
package. R does not support 64 bit integers by default, and doubles have limited precision:
But when the number is stored as 64 bit integer, jsonlite will print the full integer in the JSON output:
Currently this is only supported in toJSON
. The parser in fromJSON
still uses doubles for very large integers.