1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
### jsoncons::jsonschema::json_validator: deprecated (since 0.174.0)
```cpp
#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
<table>
<tr>
<td>instance</td>
<td>Input Json</td>
</tr>
<tr>
<td>reporter</td>
<td>A function object with signature equivalent to
<pre>
void fun(const validation_output& msg);</pre>
which accepts an argument of type <a href="validation_output.md">validation_output</a>.</td>
</tr>
</table>
#### 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](validation_error.md) for the first schema violation.
(3) `reporter` is called for each schema violation
|