Skip to content

Latest commit

 

History

History
61 lines (41 loc) · 1.54 KB

json_validator.md

File metadata and controls

61 lines (41 loc) · 1.54 KB

jsoncons::jsonschema::json_validator: deprecated (since 0.174.0)

#include <jsoncons_ext/jsonschema/jsonschema.hpp>

template <typename Json>
class json_validator

Constructor

json_validator(std::shared_ptr<json_schema<Json>> schema);

Member functions

bool is_valid(const Json& instance) const;  (1)

Json validate(const Json& instance) const;  (2)

template <typename MsgReporter>
Json validate(const Json& instance, const MsgReporter& reporter) const;  (3)

(1) Validates input JSON against a JSON Schema and returns false upon the first schema violation.

(2) Validates input JSON against a JSON Schema with a default error reporter that throws upon the first schema violation.

(3) Validates input JSON against a JSON Schema with a provided error reporter that is called for each schema violation.

Parameters

instance Input Json
reporter A function object with signature equivalent to
           void fun(const validation_output& msg);
which accepts an argument of type validation_output.

Return value

(1) true if the instance is valid, otherwise false

(2) - (3) A JSONPatch document that may be applied to the input JSON to fill in missing properties that have "default" values in the schema.

Exceptions

(2) Throws a validation_error for the first schema violation.

(3) reporter is called for each schema violation