I would like to define a c++ structure
struct Person {
std::string name;
int age;
bool student;
} person;
pass the person instance to the mapping method along with JSON data
map_json_to_struct(person, json_data)
then use the filled structure
std::cout << person.name << " : " << person.age;
Or vice versa
map_struct_to_json(person, json_data, " ");
std::cout << json_data.str() << std::endl;
get Person as JSON
{
"name": "Agent K",
"age": 42,
"student": false
}
StructMapping is trying to solve these problems
Compilation is required with -std=c++17 Mainly for:
Compiler | platform combinations on which StructMapping has been tested:
As types of member-data can be used
StructMapping is a header-only C++ library. All library files are in the include
folder.
To build examples and run tests proceed with the steps below (cmake required):
build
in StructMapping source directorybuild
directorycmake ..
command to configure your buildcmake --build .
command. On successful build you will find binary files for examples and tests (under windows tests are not build) in the bin
directoryctest
(you can get detailed output using ctest -V
)cmake --install .
command from the build tree with administrative privileges. This will install all files according to system preferences.#json #c++ #json serialization #programming-c #cplusplus