A high-performance JSON Schema validator for Rust
814
stars
1,744
commits
Rust
primary language
Sep 10, 2026
updated
A high-performance JSON Schema validator for Rust.
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let schema = json!({"maxLength": 5});
let instance = json!("foo");
// One-off validation
assert!(jsonschema::is_valid(&schema, &instance));
assert!(jsonschema::validate(&schema, &instance).is_ok());
// Build & reuse (faster)
let validator = jsonschema::validator_for(&schema)?;
// Fail on first error
assert!(validator.validate(&instance).is_ok());
// Iterate over errors
for error in validator.iter_errors(&instance) {
eprintln!("Error: {error}");
eprintln!("Location: {}", error.instance_path());
}
// Boolean result
assert!(validator.is_valid(&instance));
// Structured output (JSON Schema Output v1)
let evaluation = validator.evaluate(&instance);
for annotation in evaluation.iter_annotations() {
eprintln!(
"Annotation at {}: {:?}",
annotation.schema_location,
annotation.annotations.value()
);
}
// Generated validators are significantly faster than runtime validators,
// so prefer them when the schema is known at build time.
// Requires the `macros` feature.
// Inline schema, or `path = "schema.json"` to load from a file
#[jsonschema::validator(schema = r#"{"maxLength": 5}"#)]
struct Short;
assert!(Short::is_valid(&instance));
Short::validate(&instance)?;
Ok(())
}
You also can use it from the command line via the jsonschema-cli crate.
$ jsonschema-cli schema.json -i instance.json
See more usage examples in the documentation.
⚠️ Upgrading from older versions? Check our Migration Guide for key changes.
If you'd like to try jsonschema, you can check the WebAssembly-powered playground to see the results instantly.
The following drafts are supported:
You can check the current status on the Bowtie Report.
jsonschema outperforms other Rust JSON Schema validators in most scenarios. The numbers below are for the runtime validator, which compiles a schema into a reusable Validator:
valico and jsonschema_valid for complex schemasboon, and >5000x faster for recursive schemasWhen the schema is known at build time, the #[jsonschema::validator] macro (macros feature) generates a specialized validator at compile time. This avoids schema compilation at runtime and validates roughly 3-13x faster than the runtime validator across our benchmark schemas.
For detailed benchmarks, see our full performance comparison.
This crate requires Rust 1.85.0 or later.
By default, jsonschema uses aws-lc-rs as the TLS cryptography provider, which is the default one in reqwest.
You can opt into using ring as the TLS provider:
[dependencies]
jsonschema = {
version = "0.42",
default-features = false,
features = ["resolve-http", "resolve-file", "tls-ring"]
}
NOTE: If both tls-aws-lc-rs and tls-ring features are enabled, aws-lc-rs takes precedence.
This library draws API design inspiration from the Python jsonschema package. We're grateful to the Python jsonschema maintainers and contributors for their pioneering work in JSON Schema validation.
If you have questions, need help, or want to suggest improvements, please use GitHub Discussions.
If you find jsonschema useful, please consider sponsoring its development.
We welcome contributions! Here's how you can help:
See CONTRIBUTING.md for more details.
Licensed under MIT License.
(top 30 of 53)
Rust
90.1%
Python
4.7%
Ruby
3.3%
A high-performance JSON Schema validator for Rust
814
stars
1,744
commits
Rust
primary language
Sep 10, 2026
updated
A high-performance JSON Schema validator for Rust.
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let schema = json!({"maxLength": 5});
let instance = json!("foo");
// One-off validation
assert!(jsonschema::is_valid(&schema, &instance));
assert!(jsonschema::validate(&schema, &instance).is_ok());
// Build & reuse (faster)
let validator = jsonschema::validator_for(&schema)?;
// Fail on first error
assert!(validator.validate(&instance).is_ok());
// Iterate over errors
for error in validator.iter_errors(&instance) {
eprintln!("Error: {error}");
eprintln!("Location: {}", error.instance_path());
}
// Boolean result
assert!(validator.is_valid(&instance));
// Structured output (JSON Schema Output v1)
let evaluation = validator.evaluate(&instance);
for annotation in evaluation.iter_annotations() {
eprintln!(
"Annotation at {}: {:?}",
annotation.schema_location,
annotation.annotations.value()
);
}
// Generated validators are significantly faster than runtime validators,
// so prefer them when the schema is known at build time.
// Requires the `macros` feature.
// Inline schema, or `path = "schema.json"` to load from a file
#[jsonschema::validator(schema = r#"{"maxLength": 5}"#)]
struct Short;
assert!(Short::is_valid(&instance));
Short::validate(&instance)?;
Ok(())
}
You also can use it from the command line via the jsonschema-cli crate.
$ jsonschema-cli schema.json -i instance.json
See more usage examples in the documentation.
⚠️ Upgrading from older versions? Check our Migration Guide for key changes.
If you'd like to try jsonschema, you can check the WebAssembly-powered playground to see the results instantly.
The following drafts are supported:
You can check the current status on the Bowtie Report.
jsonschema outperforms other Rust JSON Schema validators in most scenarios. The numbers below are for the runtime validator, which compiles a schema into a reusable Validator:
valico and jsonschema_valid for complex schemasboon, and >5000x faster for recursive schemasWhen the schema is known at build time, the #[jsonschema::validator] macro (macros feature) generates a specialized validator at compile time. This avoids schema compilation at runtime and validates roughly 3-13x faster than the runtime validator across our benchmark schemas.
For detailed benchmarks, see our full performance comparison.
This crate requires Rust 1.85.0 or later.
By default, jsonschema uses aws-lc-rs as the TLS cryptography provider, which is the default one in reqwest.
You can opt into using ring as the TLS provider:
[dependencies]
jsonschema = {
version = "0.42",
default-features = false,
features = ["resolve-http", "resolve-file", "tls-ring"]
}
NOTE: If both tls-aws-lc-rs and tls-ring features are enabled, aws-lc-rs takes precedence.
This library draws API design inspiration from the Python jsonschema package. We're grateful to the Python jsonschema maintainers and contributors for their pioneering work in JSON Schema validation.
If you have questions, need help, or want to suggest improvements, please use GitHub Discussions.
If you find jsonschema useful, please consider sponsoring its development.
We welcome contributions! Here's how you can help:
See CONTRIBUTING.md for more details.
Licensed under MIT License.
(top 30 of 53)
Rust
90.1%
Python
4.7%
Ruby
3.3%