[de]Serializes any json object or value to a C++ type with the magic of compile time reflection.
See :
#include <iostream>
#include <pre/json/from_json.hpp>
// Your C++ type
struct customer {
std::string name;
size_t money_spent;
std::vector<std::string> interests;
};
// Reflection for the fields you want to load from json
BOOST_FUSION_ADAPT_STRUCT(customer,
name,
money_spent,
interests)
...
std::string string_from_network =
"{\"interests\":[\"sport articles\"], \"money_spent\":50, \"name\":\"Mrs. Fraulein\"}";
// Here you get your C++ type
customer my_customer =
pre::json::from_json<customer>(string_from_network);
std::cout << "Customer " << my_customer.name << " spent " <<
my_customer.money_spent << std::endl;
- Any Integral Types
- std::basic_string, std::string...
- Aggregate/struct adapted with Boost.Fusion
- Any Container ( i.e. std::vector, std::list...)
- Any AssociativeContainer ( i.e. std::map, std::set, std::multimap...)
- std::optional
- std::variant<Xs...>
- std::chrono::duration
Please give copyright notice :
Copyright (c) 2012-2018 Damien Buhl alias daminetreg ([email protected])