Expand description
§JSON Structure
A Rust implementation of the JSON Structure schema validation library.
JSON Structure is a type-oriented schema language for JSON, designed for defining data structures that can be validated and mapped to programming language types.
§Features
- Schema Validation: Validate JSON Structure schema documents for correctness
- Instance Validation: Validate JSON instances against JSON Structure schemas
- Source Location Tracking: Line/column tracking for error messages
- Extension Support: Support for validation, composition, and other extensions
§Quick Start
use json_structure::{SchemaValidator, InstanceValidator};
// Validate a schema
let schema_json = r#"{
"$id": "https://example.com/person",
"name": "Person",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "int32" }
},
"required": ["name"]
}"#;
let schema_validator = SchemaValidator::new();
let schema_result = schema_validator.validate(schema_json);
assert!(schema_result.is_valid());
// Validate an instance
let schema: serde_json::Value = serde_json::from_str(schema_json).unwrap();
let instance_json = r#"{"name": "Alice", "age": 30}"#;
let instance_validator = InstanceValidator::new();
let instance_result = instance_validator.validate(instance_json, &schema);
assert!(instance_result.is_valid());§Supported Types
§Primitive Types
string,boolean,nullnumber,integer(alias forint32)int8,int16,int32,int64,int128uint8,uint16,uint32,uint64,uint128float,float8,double,decimaldate,time,datetime,durationuuid,uri,binary,jsonpointer
§Compound Types
object- JSON object with typed propertiesarray- Homogeneous listset- Unique homogeneous listmap- Dictionary with string keystuple- Fixed-length typed arraychoice- Discriminated unionany- Any JSON value
§Extensions
Extensions can be enabled via the $uses keyword in schemas:
JSONStructureValidation- Validation constraints (minLength, pattern, etc.)JSONStructureConditionalComposition- Conditional composition (allOf, oneOf, etc.)JSONStructureImport- Schema importsJSONStructureAlternateNames- Alternate property namesJSONStructureUnits- Unit annotations
Structs§
- Instance
Validator - Validates JSON instances against JSON Structure schemas.
- Instance
Validator Options - Options for instance validation.
- Json
Location - Location in the source JSON document.
- Json
Source Locator - Locates positions in JSON source text.
- Schema
Validator - Validates JSON Structure schema documents.
- Schema
Validator Options - Options for schema validation.
- Validation
Error - A validation error with code, message, path, and location.
- Validation
Result - Result of validation containing errors and warnings.
Enums§
- Instance
Error Code - Error codes for instance validation errors.
- Schema
Error Code - Error codes for schema validation errors.
- Severity
- Severity level for validation messages.
Constants§
- COMPOSITION_
KEYWORDS - Conditional composition keywords that require JSONStructureConditionalComposition.
- COMPOUND_
TYPES - Compound types in JSON Structure.
- INTEGER_
TYPES - Integer types in JSON Structure.
- KNOWN_
EXTENSIONS - Known extension names.
- NUMERIC_
TYPES - Numeric types in JSON Structure.
- PRIMITIVE_
TYPES - Primitive types in JSON Structure.
- SCHEMA_
KEYWORDS - Core schema keywords.
- VALIDATION_
EXTENSION_ KEYWORDS - Validation extension keywords that require JSONStructureValidation.
Functions§
- is_
compound_ type - Returns true if the given type name is a compound type.
- is_
integer_ type - Returns true if the given type name is an integer type.
- is_
numeric_ type - Returns true if the given type name is a numeric type.
- is_
primitive_ type - Returns true if the given type name is a primitive type.
- is_
valid_ type - Returns true if the given type name is a valid JSON Structure type.