JSON Structure SDK for Rust
A Rust implementation of the JSON Structure schema validation library.
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
Features
Schema Validation
The SchemaValidator validates JSON Structure schema documents:
use ;
// With default options
let validator = new;
// With custom options
let options = SchemaValidatorOptions ;
let validator = with_options;
let result = validator.validate;
Instance Validation
The InstanceValidator validates JSON instances against schemas:
use ;
// With default options
let validator = new;
// With extended validation (enables constraint keywords)
let options = InstanceValidatorOptions ;
let validator = with_options;
let result = validator.validate;
Source Location Tracking
Errors include line and column information:
for error in result.errors
Supported Types
Primitive Types
| Type | Description |
|---|---|
string |
UTF-8 string |
boolean |
true or false |
null |
Null value |
number |
Any JSON number |
integer |
Alias for int32 |
int8 - int128 |
Signed integers |
uint8 - uint128 |
Unsigned integers |
float, double, decimal |
Floating-point numbers |
date |
Date (YYYY-MM-DD) |
time |
Time (HH:MM:SS) |
datetime |
RFC 3339 datetime |
duration |
ISO 8601 duration |
uuid |
UUID string |
uri |
URI string |
binary |
Base64-encoded bytes |
jsonpointer |
JSON Pointer |
Compound Types
| Type | Description | Required Keywords |
|---|---|---|
object |
Typed properties | properties |
array |
Homogeneous list | items |
set |
Unique list | items |
map |
String-keyed dictionary | values |
tuple |
Fixed-length array | properties + tuple |
choice |
Discriminated union | choices + selector |
any |
Any value | (none) |
Extensions
Enable extensions using $uses in your schema:
Available Extensions
- JSONStructureValidation: Validation constraints (
minLength,maxLength,pattern,minimum,maximum, etc.) - JSONStructureConditionalComposition: Composition keywords (
allOf,anyOf,oneOf,not,if/then/else) - JSONStructureImport: Schema imports (
$import,$importdefs) - JSONStructureAlternateNames: Alternate property names (
altnames) - JSONStructureUnits: Unit annotations (
unit)
Error Handling
use ;
Using Default Trait
Both validators implement Default:
use ;
let schema_validator = default;
let instance_validator = default;
Error as std::error::Error
ValidationError implements std::error::Error for integration with Rust's error handling:
use ValidationError;
License
MIT License - see LICENSE for details.