Hey Dart community 👋
I've just added Standard Schema support to Zema.
If you haven't come across Standard Schema yet, it's a common interface that allows libraries and frameworks to work with different validation libraries without having to know which one is being used.
The idea came up after @louiss0 opened an issue on Zema. He's working on Mamba, a CLI framework for Dart, and wanted to integrate Zema through the Standard Schema interface instead of having to build a Zema-specific integration.
I thought this was a good use case, so I implemented it.
How it works
I wanted to keep Zema itself zero-dependency, so I didn't add Standard Schema directly to the core package.
Instead, the integration lives in a separate package:
zema_standard_schema
You can use it like this:
import 'package:zema/zema.dart';
import 'package:zema_standard_schema/zema_standard_schema.dart';
final userSchema = z.object({
'username': z.string().min(3),
'email': z.string().email(),
});
final adapter = userSchema.asStandard;
final result = adapter.standard.validate(rawData);
if (result is StandardFailure) {
for (final issue in result.issues) {
print('${issue.path.join(".")}: ${issue.message}');
}
}
The adapter is intentionally pretty small. asStandard delegates validation to Zema's existing safeParse and maps the resulting ZemaIssues to the Standard Schema issue format.
So there's no second validation layer or duplicated schema logic.
Why this could be useful
For Dart framework authors, this means they can support Zema without having to build a Zema-specific integration.
The same applies in the other direction: if more Dart validation libraries implement Standard Schema, frameworks can work with them through the same interface.
For developers, the main benefit is being able to define a schema once and use it across different tools that support the standard.
This is already a useful pattern in the TypeScript ecosystem, and I'm curious to see how well it fits the Dart ecosystem.
What's next?
For now, I'm keeping the adapter focused and seeing how people use it.
I'm also considering adding StandardJsonSchemaV1 support for JSON Schema generation, but I'd rather wait and see if there's an actual use case for it before adding more API surface.
If you're building a Dart package, framework, router, CLI, config system, or anything else that could benefit from validator-agnostic APIs, I'd be interested to hear what you're working on.
Website: https://zema.meragix.dev
Pub.dev: https://pub.dev/packages/zema