A seventeen-part guide to data modelling with JSON Schema in .NET — from basic objects to polymorphism and pattern matching.
Json Schema Patterns in .NET
Json Schema Patterns in .NET - Data Object
Define a simple data object in JSON Schema and generate strongly typed C# with Corvus.JsonSchema, complete with properties, implicit conversions, and zero-allocation serialization.
Json Schema Patterns in .NET - Data Object Validation
Add required fields, string length limits, and numeric range constraints to a JSON Schema data object, and see how Corvus.JsonSchema enforces them in generated C# types.
Json Schema Patterns in .NET - Reusing Common Types
Use $ref and $defs to extract shared schema definitions and reuse them across properties. Corvus.JsonSchema generates a single shared .NET type, eliminating duplication.
Json Schema Patterns in .NET - Open vs. Closed Types
JSON Schema objects are open by default, allowing extra properties for forwards compatibility. Use unevaluatedProperties to close them when strict validation is needed.
Json Schema Patterns in .NET - Extending a base type
Extend an open JSON Schema type with new properties using $ref, similar to deriving from a base class in C#. The generated .NET type includes properties from both schemas.
Json Schema Patterns in .NET - Constraining a base type
Narrow the validation rules of an existing JSON Schema type by adding tighter constraints on its properties. Unlike OO overrides, constraints compose: both base and derived rules apply.
Json Schema Patterns in .NET - Creating a strongly typed array
Define typed arrays in JSON Schema using items, minItems, and maxItems. Corvus.JsonSchema generates strongly typed accessors, enumerators, and IEnumerable support for LINQ.
Json Schema Patterns in .NET - Creating an array of higher rank
Model multi-dimensional arrays (rank 2+) in JSON Schema by nesting array definitions with items. Use minItems/maxItems to fix dimensions or allow ragged arrays.
Json Schema Patterns in .NET - Working with tensors
Fixed-size numeric arrays defined in JSON Schema can be converted to and from Span<T> for use with System.Numerics.Tensors, enabling zero-allocation interop for ML and math workloads.
Json Schema Patterns in .NET - Creating tuples
JSON Schema's prefixItems keyword maps to C# ValueTuples. Combined with unevaluatedItems: false, it creates fixed-length, mixed-type arrays with strongly typed accessors.
Json Schema Patterns in .NET - Interfaces and mix-in types
Compose multiple independent schemas into a single type using allOf, the JSON Schema equivalent of implementing multiple interfaces. Generated C# types include properties from all composed schemas.
Json Schema Patterns in .NET - Pattern matching and discriminated unions
JSON Schema's oneOf keyword creates exhaustive discriminated unions, solving the two biggest problems with C# inheritance-based unions: invasiveness and missing-case bugs.
Json Schema Patterns in .NET - Polymorphism with discriminator properties
Use const-valued properties as discriminators in a oneOf union to implement the same polymorphic dispatch pattern used by System.Text.Json, illustrated with JSON Patch operations.
Json Schema Patterns in .NET - Enumerations and pattern matching
JSON Schema's enum keyword constrains values to a fixed set of strings (or mixed types). Corvus.JsonSchema generates strongly typed constants with pattern-matching support in C#.
Json Schema Patterns in .NET - Numeric enumerations and pattern matching
Plain numeric enums lose their labels in JSON Schema. Using oneOf with const and title/description preserves named, documented numeric values with full pattern-matching support in C#.
Json Schema Patterns in .NET - Maps of strings to strongly typed values
Set unevaluatedProperties to a schema to turn a JSON object into a Dictionary-like map. The generated C# type implements IReadOnlyDictionary with zero-allocation key comparisons.
Json Schema Patterns in .NET - Mapping input and output values
Convert between unrelated IJsonValue types across API, CRM, and database schemas with near-zero allocation. A schema-first alternative to AutoMapper for JSON-driven .NET applications.