pub struct Validator { /* private fields */ }Expand description
A compiled JSON Schema validator.
This structure represents a JSON Schema that has been parsed and compiled into an efficient internal representation for validation. It contains the root node of the schema tree and the configuration options used during compilation.
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn options() -> ValidationOptions
pub fn options() -> ValidationOptions
Create a default ValidationOptions for configuring JSON Schema validation.
Use this to set the draft version and other validation parameters.
§Example
let validator = jsonschema::options()
.with_draft(Draft::Draft7)
.build(&schema);Sourcepub fn new(schema: &Value) -> Result<Validator, ValidationError<'static>>
pub fn new(schema: &Value) -> Result<Validator, ValidationError<'static>>
Create a validator using the default options.
§Errors
Returns an error if the supplied schema is invalid for the selected draft or references cannot be resolved.
Sourcepub fn validate<'i>(
&self,
instance: &'i Value,
) -> Result<(), ValidationError<'i>>
pub fn validate<'i>( &self, instance: &'i Value, ) -> Result<(), ValidationError<'i>>
Validate instance against schema and return the first error if any.
§Errors
Returns the first ValidationError describing why instance does not satisfy the schema.
Sourcepub fn iter_errors<'i>(&'i self, instance: &'i Value) -> ErrorIterator<'i> ⓘ
pub fn iter_errors<'i>(&'i self, instance: &'i Value) -> ErrorIterator<'i> ⓘ
Run validation against instance and return an iterator over ValidationError in the error case.
Sourcepub fn is_valid(&self, instance: &Value) -> bool
pub fn is_valid(&self, instance: &Value) -> bool
Run validation against instance but return a boolean result instead of an iterator.
It is useful for cases, where it is important to only know the fact if the data is valid or not.
This approach is much faster, than Validator::validate.
Sourcepub fn evaluate(&self, instance: &Value) -> Evaluation
pub fn evaluate(&self, instance: &Value) -> Evaluation
Evaluate the schema and expose structured output formats.