jsonlite 0.9.12: now even lighter and faster
September 29, 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.12 appeared on CRAN which includes a completely rewritten json parser and more optimized C code for json generation. The new parser is based on yajl which is smaller and faster than libjson, and much easier to compile.
Error handling
My favorite feature of yajl is that it gives helpful error messages when parsing invalid JSON, for example:
This makes debugging much easier, especially when dealing fast changing dynamic data from the web.
Unicode parsing
The yajl parser always correctly converts escaped unicode sequences into UTF-8 characters:
Escaped unicode was already supported in the previous version of jsonlite, however it was expensive and not enabled by default. With yajl we get this for free :-)
Integer parsing
Another cool feature is that yajl parses numbers into integers when possible:
Performance
Performance of both parsing and generating JSON has again tremendously improved in this version. Some benchmarks:
If we compare this to the previous blog post we can see that generating JSON to row-based data frames (the default) is approx 2x faster than the previous version. Parsing row-based json is about 2.5x faster, and parsing column-based json is almost 5x faster!
Streaming JSON
Version 0.9.12 introduces some cool streaming functionality. This is a topic in itself and I will blog about this later in the week. Have a look at examples from the stream_in
and stream_out
manual pages till then.