ZIO Blocks Schema
Introduction
ZIO Blocks Schema is the core type system and serialization framework that provides reified structural metadata for Scala data types. It enables type-safe schema definition, validation, optics-based data access, multi-format serialization, and runtime introspection — all derived from a single Schema definition.
Core Type System:
Schema— Primary data type containing reified structure of a Scala data typeReflect— Foundational data structure containing reified structural informationBinding— Operational machinery for constructing and deconstructing valuesRegisters— Register-based design for zero-allocation construction and deconstructionStructural Types— Duck typing with ZIO Blocks schemas
Dynamic & Runtime Data:
DynamicValue— Schema-less, dynamically-typed representation of any structured valueDynamicSchema— Type-erased schema container for serialization and transportLazy— Deferred computation with monadic abstraction, memoization, and stack-safe evaluation
Navigation & Transformation:
Optics— Reflective optics for type-safe, composable access to nested data structuresDynamicOptic— Runtime path through nested data structuresSchemaExpr— Schema-aware expressions for evaluation and query language translationPatch— Type-safe, serializable transformations of data structuresModifier— Mechanism to attach metadata and configuration to schema elements
Serialization:
Codec— Base abstraction for encoding and decoding values between formatsFormats— Unified abstraction bundling serialization and deserialization for a specific formatType Class Derivation— Automatic generation of type class instances from schemasSyntax— Extension methods for fluent JSON encoding/decoding and patching
Formats:
Json— Algebraic data type for representing and manipulating JSON valuesJsonPatch— Composable patch operations transforming one JSON value into anotherJsonDiffer— Diff algorithm computing minimal patches between JSON valuesJSON Schema— First-class support for JSON Schema 2020-12Xml— Type-safe, immutable representation of XML document structures
Validation & Errors:
Validation— Declarative constraints on primitive valuesSchemaError— Structured error type for schema operationsAllows— Compile-time capability token proving a type satisfies a structural grammar
Overview
The ZIO Blocks Schema module revolves around the Schema and Reflect types, which capture the complete structural description of Scala data types at runtime. From a single schema definition, you get automatic derivation of codecs (Codec, Formats), type-safe data access (Optics, DynamicOptic), structural validation (Validation, SchemaError), patching (Patch, JsonPatch), and serialization to multiple formats (Json, Xml, JSON Schema).
The type system is powered by a register-based architecture (Registers) that eliminates boxing overhead, and supports both compile-time (Allows) and runtime (DynamicValue, DynamicSchema) type manipulation. The Deriver system (Type Class Derivation) enables automatic generation of any type class instance from schema metadata.