How to use the C# to JSON Schema converter
- Paste the C# types you want to describe: classes, records, structs and enums, including any types they use. Whole files are fine; methods and other code are ignored.
- Choose the root type (by default, the first class, record or struct) and the JSON Schema version.
- Match the options to your serializer settings, such as camelCase names and how enums are written.
- Copy the schema or download it as a
.schema.jsonfile.
What the schema describes
The schema describes the JSON that System.Text.Json writes and accepts for your types:
- Public properties, including inherited ones, positional record parameters and read-only properties (marked
readOnly). Fields, static properties and[JsonIgnore]properties are left out. - Names from
[JsonPropertyName](or Newtonsoft's[JsonProperty]), otherwise from the naming policy, using the same rules as .NET'sJsonNamingPolicy. - Types: numbers get their exact range (
intis -2147483648 to 2147483647),Guid, dates andUriget formats, collections become arrays (sets adduniqueItems), dictionaries become objects, andbyte[]becomes a base64 string. - Nullability follows nullable reference types:
stringcan't be null,string?andint?can. - Validation attributes:
[Range],[StringLength],[MinLength],[MaxLength],[Length],[RegularExpression],[EmailAddress]and[Url]. - Enums as numbers, as System.Text.Json writes them by default, or as names when the enum has
[JsonConverter(typeof(JsonStringEnumConverter))]or you choose names. - Generic types such as
Page<Product>become their own definitions, and self-referencing types use references.
A property is required if it has the required modifier, [Required] or [JsonRequired], or is a positional record parameter without a default value. Choose All non-nullable to also require every property that can't be null.
Which schema version should I choose?
Use 2020-12 for new work; it's the current version and the one used by OpenAPI 3.1. Choose Draft 7 or Draft 4 if your validator or tooling requires them. The converter uses the right keywords for each version, such as $defs or definitions.
Frequently asked questions
Is my code uploaded?
No. The C# is read and converted entirely in your browser; nothing is sent to our servers or logged.
Is the schema tested against real .NET behaviour?
Yes. Our test suite compiles sample types with the C# compiler, serializes real objects with System.Text.Json, and validates the output against the generated schemas, including deliberately broken data that must fail. Property names are checked against .NET's own naming policies.
Does it understand all C#?
It reads type declarations, not the whole language. Unusual syntax may be skipped, and types that aren't in your input allow any value; the converter lists these cases so you can paste the missing declarations. Polymorphism attributes such as [JsonDerivedType] aren't described yet.