pub fn options() -> ValidationOptionsExpand description
Create a builder for configuring JSON Schema validation options.
This function returns a ValidationOptions struct, which allows you to set various
options for JSON Schema validation. You can use this builder to specify
the draft version, set custom formats, and more.
ยงExamples
Basic usage with draft specification:
use serde_json::json;
use jsonschema::Draft;
let schema = json!({"type": "string"});
let validator = jsonschema::options()
.with_draft(Draft::Draft7)
.build(&schema)?;
assert!(validator.is_valid(&json!("Hello")));Advanced configuration:
use serde_json::json;
let schema = json!({"type": "string", "format": "custom"});
let validator = jsonschema::options()
.with_format("custom", |value| value.len() == 3)
.should_validate_formats(true)
.build(&schema)?;
assert!(validator.is_valid(&json!("abc")));
assert!(!validator.is_valid(&json!("abcd")));See ValidationOptions for all available configuration options.