Clone wiki

jsonxx / Home

JSONxx

This is a C++ library I wrote to help me generate JSON. It can also parse JSON, but it wasn't really designed with parsing in mind. I hope to address that in a future version.

What sets this library apart from others is that it is entirely streaming.

As shown in the documentation, JSON generation can look like this:

#include <iostream>
#include <jsonxx/indenting_writer.hpp>

void write_object(jsonxx::object_listener& obj) {
    jsonxx::scoped_object o(obj);

    obj.key("arr");
    obj.start_array();

    for (int i=0; i<5; ++i) obj.value(i);

    obj.end_array();
}

int main() {
    jsonxx::indenting_writer iw(std::cout);

    write_object(iw);

    return 0;
}

This code outputs:

{
    "arr": [
        0,
        1,
        2,
        3,
        4
    ]
}

Read the tutorial here.

Updated