zodart library

ZodArt — Type-safe schema validation and parsing for Dart.

Inspired by Zod, ZodArt allows you to:

  • Define runtime validation schemas for your data structures
  • Parse and transform unknown data into statically typed Dart values
  • Infer types at compile time based on the schema
  • Apply flexible validation rules and transformations
  • Build complex nested schemas (objects, arrays, nullable, etc.)

Typical use cases:

  • Parsing API responses into strongly-typed models
  • Validating form data
  • Cleaning and transforming untyped user input
  • Ensuring correctness of configuration or external data

The library is designed with:

  • Parse-first philosophy — schemas parse unknown data and produce validated values
  • Type inference — you get back strongly typed Dart values
  • Composable building blocks — validators, rules, transformations, error handling

Available types:

  • ZString
  • ZInt
  • ZDateTime
  • ZDouble
  • ZBool
  • ZArray
  • ZObject
  • ZNullable<Type>

Contributions

Contributions, ideas, and issues are welcome!

See more on: https://github.com/zzundalek/zodart

Classes

DeepCollectionEquality
Deep equality on collections.
OnNullTransformation<To>
A type-safe transformation that replaces null with a fallback value of type To.
Operation<From, To>
A class used to encapsulate transformation, validation and processing functions.
Parsing<T>
A type-safe transformation that parses an untyped Object? into a value of type T.
Processing<T>
A type-safe wrapper for processing a T value into a new T value.
Transformation<From, To>
A type-safe transformation from From to To.
Validation<T>
A type-safe wrapper for T validation logic.
ZArray<T>
Schema type representing an array of elements of type T.
ZBase<T>
The abstract base class for all ZodArt schema types.
ZBool
Schema type representing a bool value.
ZDateTime
Schema type representing a DateTime value.
ZDouble
Schema type representing a double value.
ZGenSchemaUtils<Props, ParseRes extends Object>
Utility interface for schema-generated classes providing type-safe mapping to ZObject.
ZInt
Schema type representing an int value.
ZIssue
Concrete issue that occurred during parsing, validation, or transformation.
ZIssueLocalizationService
Resolves ZIssue instances into user-friendly, localized messages.
ZLocalizationContext
A global localization context for resolving message texts.
ZNullableArray<T>
Nullable version of ZArray.
ZNullableBool
Nullable version of ZBool.
ZNullableDateTime
Nullable version of ZDateTime.
ZNullableDouble
Nullable version of ZDouble.
ZNullableInt
Nullable version of ZInt.
ZNullableObject<T extends Object>
Nullable version of ZObject.
ZNullableString
Nullable version of ZString.
ZObject<T extends Object>
Schema type representing an Object of type T.
ZodArt
Flags a class as schema definition for ZObject.
ZPath
Represents an object path, consisting of a list of ZPathItems.
ZPathItem
A single path item, either an index [n] or a property prop.
ZRes<T>
A standard result type used across parsing, validation and transformation.
ZResult<T>
A sealed class representing the result of a ZRes operation.
ZString
Schema type representing a String value.

Enums

Language
Available languages for localization

Extensions

ZErrorExt on ZError<T>
Extension that provides utility methods on ZError to improve the end-user experience.
ZIssuePatterns on ZIssue
Adds pattern-matching-related methods to ZIssue.
ZIssuesLocalizationExt on ZIssues
Extension on ZIssues (list of ZIssue) to provide localized messages easily.
ZIssuesToSuperRefinerRes on ZIssues
Extension on ZIssues that provides a utility for converting to SuperRefinerErrorRes, typically used in superRefine implementations.
ZPathItemPatterns on ZPathItem
Adds pattern-matching-related methods to ZPathItem.
ZPathPatterns on ZPath
Adds pattern-matching-related methods to ZPath.
ZResExt on ZRes<T>
Extension that provides utility methods on ZRes to improve the end-user experience.
ZResultPatterns on ZResult<T>
Adds pattern-matching-related methods to ZResult.

Typedefs

NullFallback<To> = To Function()
A fallback function that returns a value of type To when the input is null.
ObjectJson = Map<String, dynamic>
The raw JSON-like data input to be parsed according to an ObjectSchema.
ObjectMapper<T> = T Function(ObjectJson)
Maps parsed JSON data into an object of type T. Takes the successfully parsed ObjectJson and returns an instance of T.
ObjectSchema = Map<String, ZBase>
A schema defining the shape of a ZObject, mapping keys to ZBase validators or transformers.
Parser<T> = ZRes<T> Function(Object? input)
Parses untyped input (usually dynamic or JSON-like data) into a typed value T. Returns a ZRes<T> to capture parsing success or error.
Processor<T> = T Function(T val)
Processes a value and returns a new value of the same type T.
Refiner<T> = bool Function(T val)
Function used to validate a value using a custom function.
ResNullFallback<To> = ZRes<To> Function()
A fallback function that returns a ZRes containing a value of type To when the input is null.
ResProcessor<T> = ZRes<T> Function(T val)
Processes a value of type T. Returns a ZRes<T> that contains either a list of issues or the processed value.
ResRule<T> = ZRes<T> Function(T)
Validates a value of type T. Returns a ZRes<T> that contains either a list of issues or the value.
ResTransformer<From, To> = ZRes<To> Function(From)
Transforms a value of type From into type To. Returns a ZRes<To> indicating success or error.
SuperRefiner<T> = SuperRefinerErrorRes? Function(T val)
Function used to validate a value using a custom function.
SuperRefinerErrorRes = (ZIssue, {ZIssues others})
Return type for SuperRefiner when validation fails.
Transformer<From, To> = To Function(From)
Transformation functions which converts a value from From to To.
ZIssues = List<ZIssue>
A list of issues that occurred during parsing, validation, or transformation.
ZSchema = Map<String, ZBase>
A schema to define ZObject shape.