Expand description
A high-performance JSON Schema evaluator (draft 4, 6, 7, 2019-09 and 2020-12), ported from the Corvus.Text.Json V5
runtime evaluator (Corvus.Text.Json.RuntimeEvaluator).
A schema is compiled once into a node graph with pre-digested keyword data, then any number of
serde_json::Value instances are evaluated against it: fast (fail-fast, no reporting) with
Validator::is_valid, or exhaustively with a JsonSchemaResultsCollector for Basic, Detailed or Verbose
results and annotations, with the same rows (paths, messages, order) as the C# collector.
use serde_json::json;
let validator = corvus_json_schema::compile(&json!({
"type": "object",
"properties": { "id": { "type": "integer", "minimum": 1 } },
"required": ["id"]
}))
.unwrap();
assert!(validator.is_valid(&json!({ "id": 3 })));
assert!(!validator.is_valid(&json!({ "id": 0 })));Structs§
- Annotation
- An annotation extracted from verbose results.
- Compile
Options - Options for compiling a schema.
- Json
Document - JSON text parsed for evaluation. It borrows the text, for the strings that need no unescaping.
- Json
Document Array - The items of an array in a
JsonDocument. - Json
Document Object - The properties of an object in a
JsonDocument. - Json
Document Value - A value in a
JsonDocument: anInstanceforcrate::Validator::validate_instance. - Json
Parse Error - The text is not valid JSON, or nests arrays and objects too deeply.
- Json
Schema Results Collector - Collects the results of an evaluation (
JsonSchemaResultsCollector). - Schema
Compilation Error - A schema could not be compiled (an unresolvable reference, an invalid pattern).
- Schema
Evaluation Depth Error - Evaluation recursed in place beyond
max_depth(a schema that loops without consuming the instance). - Schema
Result - One result row.
- Validator
- A compiled schema. Cheap to clone and safe to share between threads.
Enums§
- Dialect
- The JSON Schema dialects the evaluator understands, in specification order.
- Kind
- The kind of a JSON value. The discriminants are the evaluator’s type bits, so a type test is one mask operation (and a match that produces a kind compiles to a table, not a jump per value).
- Results
Level - How much a results collector records.
- View
- What an instance is.
Constants§
- VERSION
- The version of this crate.
Traits§
- Array
View - The items of an array.
- Instance
- A JSON value the evaluator can read in place. Cheap to copy (a reference or a handle); values reached through it
(items, property values, strings) live as long as
'a. - Object
View - The properties of an object, in their order.
Functions§
- collect_
annotations - Annotations grouped by instance location, then keyword, then schema location fragment, with parsed values
(
JsonSchemaAnnotationProducer.WriteAnnotationsTo):{ "/name": { "title": { "#/properties/name": "Name" } } }. - compile
- Compiles a schema with the default options (2020-12 for documents without
$schema,formatas an annotation unless the vocabularies assert it). - compile_
from_ uri - Compiles the schema document at
uri, fetched throughoptions.resolve_document(or one of the standard metaschemas). - compile_
with - Compiles a schema.
- encode_
pointer_ segment - Encodes a JSON pointer segment (
~as~0,/as~1). - enumerate_
annotations - The annotations in a verbose collector’s results (
JsonSchemaAnnotationProducer.EnumerateAnnotations). - schema_
location_ fragment #followed by the schema location, percent-encoded as a URI fragment (upper-case hex, UTF-8).
Type Aliases§
- Document
Resolver - Resolves a schema document by absolute URI; returns
Noneif it is unknown. - Format
Validator - A custom format assertion over the string value (or the number’s JSON text, for numbers).