digip.org blog

Jansson 2.2 released

By Petri Lehtinen on 2011-09-03

Jansson 2.2 has been released. This release adds one new encoding function, json_dump_callback(), and fixes some minor bugs and documentation glitches. The full release notes are available here.

The new encoding function makes it possible to send encoder's output to a callback function. Here's an example:

#include <jansson.h>

/* Print the buffer's contents. */
int callback(const char *buffer, size_t size, void *x) {
    printf("%.*s\n", size, buffer);
    return 0;
}

int main() {
    json_t *root = json_pack("{s:s, s:i}", "greeting", "Hello, World!", "number", 42);
    json_dump_callback(root, callback, NULL, 0);
    return 0;
}

The third parameter to json_dump_callback() (NULL in this case) is passed through to the callback as x.

Thanks to Jonathan Landis for the initial patch!