-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_usage.cpp
More file actions
51 lines (40 loc) · 1.2 KB
/
basic_usage.cpp
File metadata and controls
51 lines (40 loc) · 1.2 KB
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
44
45
46
47
48
49
50
// Basic JsonFusion usage example
// Compile: g++ -std=c++23 -I../include basic_usage.cpp -o basic_usage
#include <JsonFusion/parser.hpp>
#include <JsonFusion/error_formatting.hpp>
#include <iostream>
#include <string>
using namespace JsonFusion;
struct Config {
std::string app_name;
int version;
bool debug_mode;
struct Server {
std::string host;
int port;
};
Server server;
};
int main() {
const char* json = R"({
"app_name": "MyApp",
"version": 1,
"debug_mode": true,
"server": {
"host": "localhost",
"port": 8080
}
})";
Config config;
auto result = Parse(config, std::string_view(json));
if (!result) {
std::cerr << ParseResultToString<Config>(result) << std::endl;
return 1;
}
std::cout << "Successfully parsed!" << std::endl;
std::cout << "App: " << config.app_name << std::endl;
std::cout << "Version: " << config.version << std::endl;
std::cout << "Debug: " << (config.debug_mode ? "ON" : "OFF") << std::endl;
std::cout << "Server: " << config.server.host << ":" << config.server.port << std::endl;
return 0;
}