| Crates.io | jsonschema |
| lib.rs | jsonschema |
| version | 0.33.0 |
| created_at | 2020-03-29 09:11:59.696721+00 |
| updated_at | 2025-08-24 17:40:15.614921+00 |
| description | JSON schema validaton library |
| homepage | |
| repository | https://github.com/Stranger6667/jsonschema |
| max_upload_size | |
| id | 224005 |
| size | 824,759 |
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));
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.
Basic output style as per JSON Schema specThe following drafts are supported:
You can check the current status on the Bowtie Report.
jsonschema outperforms other Rust JSON Schema validators in most scenarios:
valico and jsonschema_valid for complex schemasboonFor detailed benchmarks, see our full performance comparison.
This crate requires Rust 1.71.1 or later.
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.