Boost logo

Boost :

Subject: Re: [boost] JSON Parser GSoC 2013
From: Stephan Bourgeois (stephanb2_at_[hidden])
Date: 2013-04-14 13:19:05


Michael Marcin wrote:

I find the most useful interface is to just provide a datatype you're
> expecting and let the json parser try its best to do the right thing.
> For example:
> string raw_json = R"({
> data:{
> a:"hello",
> b:"world",
> c:3,
> widget:3.5
> }
> })";
> [...]
> struct my_type5
> {
> struct my_data
> {
> string a;
> string b;
> int c;
> float widget;
> } data;
> };
> // these should all just work, with maybe a little bit of
> // metaprogramming to describe the types to the json library
> json::deserialize<my_type5>( json );

I agree. This is, by far, the most intuitive interface.

I understand how this can be implemented for data types like map or even
Boost.Fusion vector in case of JSON multiple type arrays.

However, I have no idea how to implement this in the example above with a
struct! Unless of course there is no field name check nor type checking,
and the JSON values are just copied sequentially into the struct regardless
of field names. Btw I don't even know how to do this without using
C++0x extended initializer lists.

Otherwise we require some form of reflection in C++. I imagine I should
look into Boost.Serialization...? I looked at Boost.Fusion adapt_struct,
but that looks quite complicated.

Am I missing something?

Please let me know what you think.
Kind regards,
Stephan.


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