55 releases (25 breaking)
0.26.1 | Oct 29, 2024 |
---|---|
0.25.1 | Oct 25, 2024 |
0.18.0 | May 7, 2024 |
0.17.1 | Jul 5, 2023 |
0.2.0 | Mar 30, 2020 |
#10 in Web programming
1,370,595 downloads per month
Used in 166 crates
(97 directly)
720KB
17K
SLoC
jsonschema
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));
// Build & reuse (faster)
let validator = jsonschema::validator_for(&schema)?;
// Fail on first error
assert!(validator.validate(&instance));
// 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.
Highlights
- 📚 Full support for popular JSON Schema drafts
- 🔧 Custom keywords and format validators
- 🌐 Remote reference fetching (network/file)
- 🎨
Basic
output style as per JSON Schema spec - 🔗 Bindings for Python
- 🚀 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 20-470x faster than
valico
andjsonschema_valid
for complex schemas - Generally 3-20x faster than
boon
For detailed benchmarks, see our full performance comparison.
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.70 or later.
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.
Dependencies
~7–19MB
~278K SLoC