CoolProp 8.0.0
An open-source fluid property and humid air property database
SchemaValidation.cpp
Go to the documentation of this file.
2
3#include <string>
4
7
8namespace CoolProp {
9
10void 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
19std::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