Boost logo

Boost :

Subject: Re: [boost] JSON Parser GSoC 2013
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-04-12 11:53:47

Arindam Mukherjee wrote:
> In JSON we typically deal with maps and arrays. The arrays themselves could
> have arbitrary types (string, object, array, numeric, boolean, null) as
> elements. The key types in the maps are always strings and the value types
> in the maps could be anything that can appear in an array, including
> another map or array.
> Due to this, I'd imagine being able to use Boost.Variant or Boost.Any in a
> list and as a value_type in a map would help.


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"({


struct my_type1
     map<string,string> data;

struct my_type2
     map<string,variant<string,int,double>> data;

struct my_type3
     map<string,any> data;

struct my_type4
     unordered_map<string,string> data;

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_type1>( json );
json::deserialize<my_type2>( json );
json::deserialize<my_type3>( json );
json::deserialize<my_type4>( json );
json::deserialize<my_type5>( json );

struct my_type6
     map<string,int> data;

// runtime error can't meaningfully convert
// "hello" to an int
json::deserialize<my_type6>( json );

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