CoolProp
8.0.0
An open-source fluid property and humid air property database
src
SchemaValidation.cpp
Go to the documentation of this file.
1
#include "
CoolProp/SchemaValidation.h
"
2
3
#include <string>
4
5
#include "
CoolProp/Exceptions.h
"
6
#include "
CoolProp/detail/json.h
"
7
8
namespace
CoolProp
{
9
10
void
validate_json_against_schema
(
const
std::string& instance_json,
const
std::string& schema_json) {
11
std::string errstr;
12
// cpjson::validate_schema(schemaJson, inputJson, errstr) — Valijson-backed. Schema first.
13
cpjson::schema_validation_code
code =
cpjson::validate_schema
(schema_json, instance_json, errstr);
14
if
(code !=
cpjson::SCHEMA_VALIDATION_OK
) {
15
throw
ValueError
(std::string(
"schema validation failed: "
) + errstr);
16
}
17
}
18
19
std::string
to_canonical_json_str
(
const
std::string& json_str) {
20
// nlohmann::json is std::map-backed, so object keys serialize sorted at every
21
// level — the canonical (deterministic, key-sorted) form. Arrays keep order.
22
return
cpjson::parse
(json_str).dump();
23
}
24
25
}
// namespace CoolProp
Generated by
1.9.4