Require C++20
#include <iostream>
#include <pfrjson/pfrjson.h>
struct Sub {
string sub;
};
struct Root {
int a{};
double b{};
string c;
bool d{};
Sub sub;
optional<Sub> nullsub;
optional<Sub> opsub;
};
int main() {
// Prepare data to serialize
Root root{
1,
2.5,
"Test C++",
false,
{
"This is Sub."
},
nullopt,
Sub{
"That's good"
}
};
// Serialize to json
string json_str = PfrJson::serialize<RP::PrettyWriter<RP::StringBuffer>>(root);
cout << json_str << endl;
// Prepare deserialize slot
Root desc;
// Deserialize json
PfrJson::deserialize(json_str, desc);
cout << desc.sub.sub << endl;
}