schemantic
1.0.0, released 6 weeks ago by genkit.dev
Generate type-safe data classes and runtime JSON Schemas from abstract class definitions.
What it does
Schemantic is a library that generates fully-typed Dart data classes and runtime-accessible JSON Schemas from simple abstract class definitions. It features built-in JSON serialization, runtime data validation against schemas, and support for recursive structures, union types, and custom types.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to generate runtime JSON Schemas alongside immutable-style data classes from code definitions.
- You want built-in runtime validation of JSON payloads against generated schemas.
- You work with AI tools or structured output requirements that depend on strict JSON schemas.
Skip it when
- You are looking for state management solutions or UI widget component libraries.
- You do not want to use code generation and build_runner in your workflow.
Strengths
- First-class runtime JSON schemas accessible from generated data classes.
- Built-in serialization and runtime validation.
- Supports recursive schemas and union types (AnyOf).
Weaknesses
- Requires build_runner and a separate builder package for code generation.
- Adds an extra step to the development workflow for schema modifications.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 1
Add schemantic, schemantic_builder, and build_runner as dependencies, then run build_runner to generate part files.
import 'package:schemantic/schemantic.dart';
part 'user.g.dart';
@Schema()
abstract class $User {
String get name;
int? get age;
bool get isAdmin;
}Alternatives
Packages that do the same job and could replace schemantic.
- freezed_annotation
Choose freezed if you primarily want advanced union types, deep copying, and immutable data classes rather than runtime JSON schema generation.
78Compare
Works with
Packages commonly used together with schemantic: ones it builds on, ones built on it, and its own family.
- json_schema_builderschemantic depends on itBuild and validate JSON Schemas in Dart with a fluent, type‑safe API
- genkitBuilt on schemanticGenerative AI library for Dart and Flutter supporting text generation, tools, and flows.
- genkit_llamadartBuilt on schemanticGenkit Dart plugin for local AI through llamadart: GGUF, LiteRT-LM, chat, tool calling, and embeddings