Skip to main content

validate

Function validate 

Source
pub fn validate(schema: &JsonSchema, instance: &Value) -> ValidationResult
Expand description

Validates a JSON instance against a schema. Collects all validation errors and returns them in a single result (no fail-fast).

Validates using the type (object, string, integer, number), required, and properties keywords. Resolves fragment-only $ref against the root schema; additional properties are allowed.

§Errors

Returns Err(errors) when the instance does not conform to the schema, with one or more ValidationError values describing each failure.

§Example

use json_schema_rs::{JsonSchema, validate};
use serde_json::json;

let schema: JsonSchema = serde_json::from_str(r#"{"type":"object","properties":{"name":{"type":"string"}}}"#).unwrap();
let instance = json!({"name": "Alice"});
let result = validate(&schema, &instance);
assert!(result.is_ok());