Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 2.08 KB

README.md

File metadata and controls

62 lines (46 loc) · 2.08 KB

pipeline status for win10, macOS & linux.

pre::from_ or to_ json

[de]Serializes any json object or value to a C++ type with the magic of compile time reflection.

Examples

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;

Supported types

License

Boost Software License.

Please give copyright notice :

Copyright (c) 2012-2018 Damien Buhl alias daminetreg ([email protected])