Boost logo

Boost :

Subject: Re: [boost] JSON Parsing Library for GSoC 14
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-03-06 08:35:38


2014-03-06 18:34 GMT+08:00 Bjorn Reese <breese_at_[hidden]>:

> 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

I'm confused. Your json::iarchive takes iterators not istream.
I see there's stream_oarchive but no stream_iarchive, something I missed?

and (2) it supports various
> binary encodings with a structure similar to JSON.
>
> I really ought to write the documentation of this library...

After a glance at some of the tests, say, the 'person' example
in oarchive_suite.cpp, I wonder why it outputs value as array instead of
object:

    {"name": "Kant", "age": 127}

> 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.

What's the benefit of dynamic-cpp over Boost.Any?
If you want more generic, I guess that's what Boost.TypeErasure is for.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk