Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
json_validation.cpp
Go to the documentation of this file.
2#include <fstream>
3#include <iostream>
4#include <string>
5
6nlohmann::json import_json(std::string file_path) {
7 std::ifstream input(file_path);
8 return nlohmann::json::parse(input);
9}
10
12 const nlohmann::json &imported_data,
13 const nlohmann::json &schema
14) {
15 nlohmann::json_schema::json_validator validator;
16
17 try {
18 validator.set_root_schema(schema);
19 } catch (const std::exception &e) {
20 std::cerr << "Schema validation failed: " << e.what() << std::endl;
21 exit(1);
22 }
23
24 try {
25 auto data_validation_result = validator.validate(imported_data);
26 return true;
27 } catch (const std::exception &e) {
28 return false;
29 }
30}
bool json_matches_schema(const nlohmann::json &imported_data, const nlohmann::json &schema)
nlohmann::json import_json(std::string file_path)