Skip to content

jmuncaster/jws

Repository files navigation

JSON With Schema

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.

Getting Started

Prerequisites

Add a snapshot of this repository to your source code or add it as a git submodule.

Build

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)

Example

#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;
}

Build Examples and Tests

To build the examples and tests run:

$ mkdir -p build && cd build
$ cmake -D BUILD_EXAMPLES=ON -D BUILD_TESTS=ON ..
$ make

Run Tests

./test_jws --working_dir /path/to/jws

About

JSON with Schema

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages