This library is a wrapper around nlohmann/json for parsing JSON and pboettch/json-schema-validator for validating JSON against a schema described by JSON-Schema draft4.
Add a snapshot of this repository to your source code or add it as a git submodule.
These instructions assume you are using cmake.
In your CMakeLists.txt, add:
add_subdirectory(path/to/jws jws)
add_executable(myapp main.cpp)
target_link_libraries(myapp jws)#include <jws/json_with_schema.hpp>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 3) {
cout << "usage: validate_json <schema.json> <document.json>" << endl;
return 1;
}
auto validator = load_validator(argv[1]);
auto document = load_json(argv[2]);
validator.validate(document); // throws on error
cout << "document validated" << endl;
return 0;
}To build the examples and tests run:
$ mkdir -p build && cd build
$ cmake -D BUILD_EXAMPLES=ON -D BUILD_TESTS=ON ..
$ make./test_jws --working_dir /path/to/jws