Skip to content

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 - Data Object

Json Schema Patterns in .NET - Data Object

Matthew Adams

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

Json Schema Patterns in .NET - Data Object Validation

Matthew Adams

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

Json Schema Patterns in .NET - Reusing Common Types

Matthew Adams

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 Patterns in .NET - Open vs. Closed Types

Matthew Adams

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

Json Schema Patterns in .NET - Extending a base type

Matthew Adams

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

Json Schema Patterns in .NET - Constraining a base type

Matthew Adams

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

Json Schema Patterns in .NET - Creating a strongly typed array

Matthew Adams

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

Json Schema Patterns in .NET - Creating an array of higher rank

Matthew Adams

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

Json Schema Patterns in .NET - Working with tensors

Matthew Adams

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 Patterns in .NET - Creating tuples

Matthew Adams

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

Json Schema Patterns in .NET - Interfaces and mix-in types

Matthew Adams

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 Patterns in .NET - Pattern matching and discriminated unions

Matthew Adams

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

Json Schema Patterns in .NET - Polymorphism with discriminator properties

Matthew Adams

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 Patterns in .NET - Enumerations and pattern matching

Matthew Adams

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

Json Schema Patterns in .NET - Numeric enumerations and pattern matching

Matthew Adams

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

Json Schema Patterns in .NET - Maps of strings to strongly typed values

Matthew Adams

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

Json Schema Patterns in .NET - Mapping input and output values

Matthew Adams

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.