digip.org blog

Jansson 2.4 released

By Petri Lehtinen on 2012-09-23

Jansson 2.4 has been released. This release adds new features and fixes a few bugs and documentation issues. It also adds support for building the library on Microsoft Visual Studio. The full release notes are available here.

New features

A new macro, json_boolean(), was added. It returns either the JSON true or JSON false value based on its argument. It's useful in situations like this:

json_t *value;
int yes = read_value_from_somewhere();
value = json_boolean(yes);  /* false if yes == 0, true otherwise */

It's now possible to decode JSON with a callback providing the source JSON text. The new json_load_callback() function calls a callback repeatedly to read the source JSON. This is useful when the JSON data is received from a custom stream, for example.

JSON allows, but doesn't require, escaping / characters with \/. This is useful when JSON is embedded in a HTML <script> tag, because the string </ must not occur inside a <script> tag. When using the new JSON_ESCAPE_SLASH encoding flag, Jansson now escapes /'s for you.

Bug fixes

Until now, it has been possible to make Jansson produce invalid JSON by creating a real value with an Inf or NaN special value. json_real() and json_real_set() now check for these special values and refuse to accept them, returning -1 to signal an error. (As a matter of fact, json_real_set() returned 0 even on other errors, and this was fixed, too.)

Windows support

It's now possible to build Jansson on Windows with Microsoft Visual Studio. All the build errors have been fixed, and solution and project files for Visual Studio 2010 are included in the win32/vs2010/ directory in the source distribution.