json_structure/
lib.rs

1//! # JSON Structure
2//!
3//! A Rust implementation of the JSON Structure schema validation library.
4
5#![allow(clippy::too_many_arguments)]
6#![allow(clippy::needless_borrows_for_generic_args)]
7#![allow(clippy::collapsible_match)]
8//!
9//! JSON Structure is a type-oriented schema language for JSON, designed for defining
10//! data structures that can be validated and mapped to programming language types.
11//!
12//! ## Features
13//!
14//! - **Schema Validation**: Validate JSON Structure schema documents for correctness
15//! - **Instance Validation**: Validate JSON instances against JSON Structure schemas
16//! - **Source Location Tracking**: Line/column tracking for error messages
17//! - **Extension Support**: Support for validation, composition, and other extensions
18//!
19//! ## Quick Start
20//!
21//! ```rust
22//! use json_structure::{SchemaValidator, InstanceValidator};
23//!
24//! // Validate a schema
25//! let schema_json = r#"{
26//!     "$id": "https://example.com/person",
27//!     "name": "Person",
28//!     "type": "object",
29//!     "properties": {
30//!         "name": { "type": "string" },
31//!         "age": { "type": "int32" }
32//!     },
33//!     "required": ["name"]
34//! }"#;
35//!
36//! let schema_validator = SchemaValidator::new();
37//! let schema_result = schema_validator.validate(schema_json);
38//! assert!(schema_result.is_valid());
39//!
40//! // Validate an instance
41//! let schema: serde_json::Value = serde_json::from_str(schema_json).unwrap();
42//! let instance_json = r#"{"name": "Alice", "age": 30}"#;
43//!
44//! let instance_validator = InstanceValidator::new();
45//! let instance_result = instance_validator.validate(instance_json, &schema);
46//! assert!(instance_result.is_valid());
47//! ```
48//!
49//! ## Supported Types
50//!
51//! ### Primitive Types
52//! - `string`, `boolean`, `null`
53//! - `number`, `integer` (alias for `int32`)
54//! - `int8`, `int16`, `int32`, `int64`, `int128`
55//! - `uint8`, `uint16`, `uint32`, `uint64`, `uint128`
56//! - `float`, `float8`, `double`, `decimal`
57//! - `date`, `time`, `datetime`, `duration`
58//! - `uuid`, `uri`, `binary`, `jsonpointer`
59//!
60//! ### Compound Types
61//! - `object` - JSON object with typed properties
62//! - `array` - Homogeneous list
63//! - `set` - Unique homogeneous list
64//! - `map` - Dictionary with string keys
65//! - `tuple` - Fixed-length typed array
66//! - `choice` - Discriminated union
67//! - `any` - Any JSON value
68//!
69//! ## Extensions
70//!
71//! Extensions can be enabled via the `$uses` keyword in schemas:
72//!
73//! - `JSONStructureValidation` - Validation constraints (minLength, pattern, etc.)
74//! - `JSONStructureConditionalComposition` - Conditional composition (allOf, oneOf, etc.)
75//! - `JSONStructureImport` - Schema imports
76//! - `JSONStructureAlternateNames` - Alternate property names
77//! - `JSONStructureUnits` - Unit annotations
78
79mod error_codes;
80mod instance_validator;
81mod json_source_locator;
82mod schema_validator;
83mod types;
84
85pub use error_codes::{InstanceErrorCode, SchemaErrorCode};
86pub use instance_validator::InstanceValidator;
87pub use json_source_locator::JsonSourceLocator;
88pub use schema_validator::SchemaValidator;
89pub use types::{
90    InstanceValidatorOptions, JsonLocation, SchemaValidatorOptions, Severity, ValidationError,
91    ValidationResult,
92};
93
94// Re-export type constants
95pub use types::{
96    is_compound_type, is_integer_type, is_numeric_type, is_primitive_type, is_valid_type,
97    COMPOSITION_KEYWORDS, COMPOUND_TYPES, INTEGER_TYPES, KNOWN_EXTENSIONS, NUMERIC_TYPES,
98    PRIMITIVE_TYPES, SCHEMA_KEYWORDS, VALIDATION_EXTENSION_KEYWORDS,
99};