Skip to main content

validator_for

Function validator_for 

Source
pub fn validator_for(
    schema: &Value,
) -> Result<Validator, ValidationError<'static>>
Expand description

Create a validator for the input schema with automatic draft detection and default options.

§Examples

use serde_json::json;

let schema = json!({"minimum": 5});
let instance = json!(42);

let validator = jsonschema::validator_for(&schema)?;
assert!(validator.is_valid(&instance));

§Errors

Returns an error if the schema is invalid or external references cannot be resolved.

§Panics

This function must not be called from within an async runtime if the schema contains external references that require network requests, or it will panic when attempting to block. Use async_validator_for for async contexts, or run this in a separate blocking thread via tokio::task::spawn_blocking.