Skip to main content

Crate corvus_json_schema

Crate corvus_json_schema 

Source
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.
CompileOptions
Options for compiling a schema.
JsonDocument
JSON text parsed for evaluation. It borrows the text, for the strings that need no unescaping.
JsonDocumentArray
The items of an array in a JsonDocument.
JsonDocumentObject
The properties of an object in a JsonDocument.
JsonDocumentValue
A value in a JsonDocument: an Instance for crate::Validator::validate_instance.
JsonParseError
The text is not valid JSON, or nests arrays and objects too deeply.
JsonSchemaResultsCollector
Collects the results of an evaluation (JsonSchemaResultsCollector).
SchemaCompilationError
A schema could not be compiled (an unresolvable reference, an invalid pattern).
SchemaEvaluationDepthError
Evaluation recursed in place beyond max_depth (a schema that loops without consuming the instance).
SchemaResult
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.
JsonValidationError
Why JSON text could not be validated.
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).
ResultsLevel
How much a results collector records.
View
What an instance is.

Constants§

VERSION
The version of this crate.

Traits§

ArrayView
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.
ObjectView
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, format as an annotation unless the vocabularies assert it).
compile_from_uri
Compiles the schema document at uri, fetched through options.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§

DocumentResolver
Resolves a schema document by absolute URI; returns None if it is unknown.
FormatValidator
A custom format assertion over the string value (or the number’s JSON text, for numbers).