Jsonschema
A high-performance JSON Schema validator for Rust
Install / Use
/learn @Stranger6667/JsonschemaREADME
jsonschema
<img alt="crates.io" src="https://img.shields.io/crates/v/jsonschema.svg?style=flat-square&color=fc8d62&logo=rust" height="20"> <img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-jsonschema-66c2a5?style=flat-square&labelColor=555555&logo=docs.rs" height="20"> <img alt="build status" src="https://img.shields.io/github/actions/workflow/status/Stranger6667/jsonschema/ci.yml?branch=master&style=flat-square" height="20"> <img alt="codecov.io" src="https://img.shields.io/codecov/c/gh/Stranger6667/jsonschema?logo=codecov&style=flat-square&token=B1EnafGlRL" height="20"> <img alt="Supported Dialects" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fbowtie.report%2Fbadges%2Frust-jsonschema%2Fsupported_versions.json&style=flat-square">
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()
);
}
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.
Highlights
- 📚 Full support for popular JSON Schema drafts
- 🔧 Custom keywords and format validators
- 🌐 Blocking & non-blocking remote reference fetching (network/file)
- 🎨 Structured Output v1 reports (flag/list/hierarchical)
- ✨ Meta-schema validation for schema documents, including custom metaschemas
- 🔗 Bindings for Python and Ruby
- 🚀 WebAssembly support
- 💻 Command Line Interface
Supported drafts
The following drafts are supported:
You can check the current status on the Bowtie Report.
Notable Users
- Tauri: Config validation
- Apollo Router: Config file validation
- qsv: CSV record validation with custom keyword & format validator
Performance
jsonschema outperforms other Rust JSON Schema validators in most scenarios:
- Up to 75-645x faster than
valicoandjsonschema_validfor complex schemas - Generally 2-52x faster than
boon, and >5000x faster for recursive schemas
For detailed benchmarks, see our full performance comparison.
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.83.0 or later.
TLS Configuration
By default, jsonschema uses aws-lc-rs as the TLS cryptography provider, which is the default one in reqwest.
Using Ring Instead
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.
Acknowledgements
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.
Support
If you have questions, need help, or want to suggest improvements, please use GitHub Discussions.
Sponsorship
If you find jsonschema useful, please consider sponsoring its development.
Contributing
We welcome contributions! Here's how you can help:
- Share your use cases
- Implement missing keywords
- Fix failing test cases from the JSON Schema test suite
See CONTRIBUTING.md for more details.
License
Licensed under MIT License.
Related Skills
himalaya
347.0kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
taskflow
347.0kname: taskflow description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layer
claude-opus-4-5-migration
107.8kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
