Benzene.JsonSchema
0.0.3-alpha.3
dotnet add package Benzene.JsonSchema --version 0.0.3-alpha.3
NuGet\Install-Package Benzene.JsonSchema -Version 0.0.3-alpha.3
<PackageReference Include="Benzene.JsonSchema" Version="0.0.3-alpha.3" />
<PackageVersion Include="Benzene.JsonSchema" Version="0.0.3-alpha.3" />
<PackageReference Include="Benzene.JsonSchema" />
paket add Benzene.JsonSchema --version 0.0.3-alpha.3
#r "nuget: Benzene.JsonSchema, 0.0.3-alpha.3"
#:package Benzene.JsonSchema@0.0.3-alpha.3
#addin nuget:?package=Benzene.JsonSchema&version=0.0.3-alpha.3&prerelease
#tool nuget:?package=Benzene.JsonSchema&version=0.0.3-alpha.3&prerelease
JSON Schema Validation
JSON Schema is the standard, language-neutral way to describe and validate the shape of JSON documents. Validating with JSON Schema means the contract is the validator: the same schema document that describes a payload in your spec can reject non-conforming payloads at the door — with no C# validator classes to write, and no way for the two to drift apart.
Integration with Benzene
JSON Schema validation runs as pipeline middleware over the raw request body, before deserialization — the natural place for a document validator (it checks the wire JSON itself, so it also catches malformed or missing bodies).
For each message it obtains a schema for the current topic and evaluates the body against it. A failing body short-circuits with a ValidationError result whose payload is an array of property-scoped messages — the same failure contract as Benzene.FluentValidation and Benzene.DataAnnotations:
["/name: Value is longer than 5 characters", "/lines/0/sku: Required properties [\"sku\"] are not present"]
A null schema for a topic means "no validation" and the message passes through.
.UseJsonSchema()
.UseMessageHandlers()
Where schemas come from
- Generated (default):
DefaultJsonSchemaProviderderives a schema from the registered handler's request type (JsonSchema.Net.Generation, draft 2020-12, camelCase). - Bring your own: register hand-authored schema documents per request type — the same documents you can serve from the spec via
Benzene.Schema.OpenApi'sSuppliedSchemaCatalog, so published contract and runtime validation stay aligned:
var schemas = new SuppliedJsonSchemaCatalog()
.AddJson(typeof(CreateOrderMessage), File.ReadAllText("schemas/create-order.json"));
services.UsingBenzene(x => x.AddSuppliedJsonSchemas(schemas));
- Fully custom: implement
IJsonSchemaProvider<TContext>to source schemas from anywhere (a registry service, embedded resources, per-tenant stores).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Benzene.Abstrations.Pipelines (>= 0.0.3-alpha.3)
- Benzene.Core.MessageHandlers (>= 0.0.3-alpha.3)
- Benzene.Core.Middleware (>= 0.0.3-alpha.3)
- JsonSchema.Net (>= 9.2.2)
- JsonSchema.Net.Generation (>= 7.3.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.0.3-alpha.3 | 54 | 8/19/2026 |
| 0.0.3-alpha.2 | 51 | 8/19/2026 |
| 0.0.3-alpha.1 | 50 | 8/19/2026 |
| 0.0.2.18-alpha | 58 | 7/14/2026 |
| 0.0.2.17-alpha | 55 | 7/13/2026 |
| 0.0.2.16-alpha | 55 | 7/11/2026 |
| 0.0.2.15-alpha | 144 | 2/7/2025 |
| 0.0.2.14-alpha | 136 | 2/7/2025 |
| 0.0.2.13-alpha | 126 | 2/6/2025 |
| 0.0.2.12-alpha | 129 | 12/19/2024 |
| 0.0.2-alpha.6 | 48 | 8/13/2026 |
| 0.0.2-alpha.5 | 52 | 8/13/2026 |
| 0.0.2-alpha.4 | 62 | 8/10/2026 |
| 0.0.2-alpha.3 | 48 | 8/10/2026 |
| 0.0.2-alpha.2 | 50 | 7/23/2026 |
| 0.0.2-alpha.1 | 60 | 7/23/2026 |