JSON Schema Validator Core
A lightning-fast JSON Schema validation library written in Rust with comprehensive error reporting and multi-language bindings support. Designed for high-performance applications requiring strict JSON validation with detailed, actionable error messages.
Features
- Lightning Fast - Optimized Rust implementation with minimal allocations
- Comprehensive Validation - Full JSON Schema Draft 7 support (with Draft 4, 6, 2019-09, 2020-12 features)
- Detailed Error Messages - Rich error context with instance paths, schema paths, and custom messages
- Custom Formats - Extensible format validation system
- Custom Keywords - Support for custom validation keywords
- Multi-Language Support - C FFI and WebAssembly bindings
- Memory Safe - Built with Rust's safety guarantees
- Zero Dependencies - Core validation logic uses minimal external dependencies
- Format Validation - Built-in support for email, URI, date, datetime, IPv4, IPv6, UUID formats
Quick Start
Rust Usage
Add this to your Cargo.toml
:
[]
= "1.0.0"
Basic example:
use ;
use json;
Advanced Configuration
use ;
use HashMap;
let mut custom_formats = new;
custom_formats.insert;
let options = ValidationOptions ;
let schema = json!;
let validator = new.unwrap;
C FFI Usage
Build the shared library:
Use in C/C++:
extern char* ;
extern void ;
int
WebAssembly Usage
import init from './pkg/json_schema_validator_core.js';
Validation Features
Type Validation
null
,boolean
,integer
,number
,string
,array
,object
- Support for multiple types:
{"type": ["string", "null"]}
String Validation
minLength
/maxLength
- Length constraintspattern
- Regular expression matchingformat
- Built-in format validation (email, uri, date, datetime, ipv4, ipv6, uuid)
Number Validation
minimum
/maximum
- Value constraintsexclusiveMinimum
/exclusiveMaximum
- Exclusive boundsmultipleOf
- Divisibility constraints
Array Validation
minItems
/maxItems
- Length constraintsuniqueItems
- Uniqueness enforcementitems
- Item schema validationadditionalItems
- Additional item handling
Object Validation
minProperties
/maxProperties
- Property count constraintsrequired
- Required property enforcementproperties
- Property schema validationadditionalProperties
- Additional property handlingpatternProperties
- Pattern-based property validation
Generic Validation
enum
- Enumeration validationconst
- Constant value validationallOf
/anyOf
/oneOf
- Schema compositionnot
- Schema negation
Error Structure
Each validation error provides detailed context:
Example error output:
Performance
Optimized for high-throughput applications:
- Schema Compilation - Pre-compile schemas for faster validation
- Memory Efficiency - Minimal allocations during validation
- Early Exit - Optional short-circuit mode for faster validation
- Regex Caching - Compiled regex patterns are cached
Benchmark results on a modern CPU:
- Simple object validation: ~2M validations/second
- Complex nested validation: ~500K validations/second
- Large array validation: ~1M items/second
Schema Draft Support
Feature | Draft 4 | Draft 6 | Draft 7 | 2019-09 | 2020-12 |
---|---|---|---|---|---|
Core Keywords | ✅ | ✅ | ✅ | ✅ | ✅ |
Format Validation | ✅ | ✅ | ✅ | ✅ | ✅ |
Schema Composition | ✅ | ✅ | ✅ | ✅ | ✅ |
Conditional Schemas | ❌ | ❌ | ✅ | ✅ | ✅ |
Annotations | ❌ | ❌ | ✅ | ✅ | ✅ |
Multi-Language Bindings
Planned Language Support
- JavaScript/TypeScript - WebAssembly bindings ✅
- Python - PyO3 bindings (planned)
- Go - CGO bindings (planned)
- Java - JNI bindings (planned)
- C#/.NET - P/Invoke bindings (planned)
- Node.js - Native addon (planned)
FFI Safety
All exports are designed with safety in mind:
- Null pointer validation
- UTF-8 string validation
- Proper memory management
- Clear error handling
- Thread-safe operations
Building
Requirements
- Rust 1.70 or later
- Cargo
Development Build
Release Build
WebAssembly Build
Running Tests
Running Benchmarks
Building Documentation
Use Cases
Perfect for:
- API Validation - Validate incoming JSON requests
- Configuration Validation - Ensure config files are correct
- Data Pipeline Validation - Validate data transformations
- Form Validation - Client and server-side form validation
- Message Queue Validation - Validate message formats
- Database Schema Validation - Ensure data consistency
- Microservices - Service contract validation
Examples
REST API Validation
use ;
// Define API schema
let user_schema = json!;
let validator = new.unwrap;
// Validate incoming requests
Configuration Validation
// Database configuration schema
let config_schema = json!;
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for your changes
- Ensure tests pass (
cargo test
) - Run benchmarks (
cargo bench
) - Commit your changes (
git commit -am 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Code Style
- Follow standard Rust conventions
- Run
cargo fmt
before committing - Run
cargo clippy
and fix any warnings - Add tests for new functionality
- Update documentation as needed
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Changelog
v1.0.0 (2025-09-20)
- Initial release
- Full JSON Schema Draft 7 support
- High-performance validation engine
- Comprehensive error reporting
- C FFI exports
- WebAssembly bindings
- Format validation (email, URI, date, datetime, IPv4, IPv6, UUID)
- Custom format and keyword support
- Extensive test suite
Related Projects
- jsonschema - Another Rust JSON Schema validator
- ajv - JavaScript JSON Schema validator
- jsonschema - Python JSON Schema validation
Acknowledgments
- JSON Schema specification maintainers
- The Rust community for excellent crates and tooling
- Contributors to the serde ecosystem
Built with Rust 🦀 for speed and safety.