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: http://protoc.sourceforge.net/ 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; or 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: http://dynamic-cpp.googlecode.com/ 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: http://boost.2283326.n4.nabble.com/JSON-Parser-GSoC-2013-td4645117.html
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.