Boost logo

Boost :

Subject: Re: [boost] JSON Parsing Library for GSoC 14
From: Bjorn Reese (breese_at_[hidden])
Date: 2014-03-06 05:34:12

On 03/03/2014 10:22 AM, Sebastian Theophil wrote:

> But there are only two libraries AFAIK that parse JSON to C++ structs using serialization adaptors:

Here is one that integrates with Boost.Serialization:

You can parse JSON directly into C++ structures:

   std::string input("[1,2,3]");
   struct my_struct { int x, y, z; } result;

   protoc::json::iarchive archive(input.begin(), input.end());
   archive >> result;


   std::string input("[1,2,3]");
   std::vector<int> result;

   protoc::json::iarchive archive(input.begin(), input.end());
   archive >> result;

You can also parse generic JSON into a DOM based on boost::variant. I
currently use dynamic-cpp:

Parsing into this DOM follows the same pattern as above:

   std::string input("[1,2,[3,4]]");
   dynamic::var result;

   protoc::json::iarchive archive(input.begin(), input.end());
   archive >> dom;

The protoc project has a couple of other advantages: (1) it supports
streaming, which means that you can parse or construct JSON without
requiring all data to be in memory at once, and (2) it supports various
binary encodings with a structure similar to JSON.

I really ought to write the documentation of this library...

> There has been a discussion about last year’s GSoC mentioning further desirable properties of a JSON library:

Indeed, and most of these desiderata still applies.

With the protoc library, we can focus on the integration with other
Boost libraries, such as Boost.Fusion, or replacing the JSON
implementation of Boost.PropertyTree.

Another suitable GSoC project (for the student who wants to do meta-
programming) could be to write a more generic version of dynamic-cpp.
I have already written parts of it.

Boost list run by bdawes at, gregod at, cpdaniel at, john at