-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_json.cpp
More file actions
43 lines (34 loc) · 813 Bytes
/
to_json.cpp
File metadata and controls
43 lines (34 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <pre/json/to_json.hpp>
#include <pre/json/mapping.hpp>
struct customer {
std::string name;
size_t money_spent;
std::vector<std::string> interests;
bool is_private;
};
BOOST_FUSION_ADAPT_STRUCT(customer,
name,
money_spent,
interests,
is_private)
int main() {
{
customer my_customer{
"Mr. Dupond",
1000,
{"sport articles", "food", "tools"},
true
};
std::cout << pre::json::to_json(my_customer) << std::endl;
// with remapping
std::cout << "With property 'is_private' mapped to 'private':\n"
<< pre::json::to_json(
my_customer,
[](auto &jdoc) {
pre::json::remap_property(jdoc, "/is_private"_json_pointer, "/private"_json_pointer);
})
<< std::endl;
}
return 0;
}