JSON to C# Class Generator
Turn a JSON response into C# classes that deserialise on the first try: nullable annotations computed from every record, initialisers that keep the build warning-free, and [JsonPropertyName] wherever C# naming disagrees with the wire.
Runs entirely in your browser — your JSON is never uploaded.
Free generation covers up to 1,000,000 characters per document — what Pro adds. The JSON you paste never leaves the tab; inference runs in your browser.
How to generate C# classes from JSON
- Paste a JSON object or array or load the example: two orders whose item lists disagree, which is exactly where single-sample generators get it wrong.
- Name the root class and the namespace The root name becomes the first class and the file name. The namespace is optional — leave it blank for a snippet you paste into an existing project.
- Choose the serialiser style System.Text.Json attributes are on by default. Turn them off if you already configure PropertyNameCaseInsensitive or use a naming policy.
- Copy or download the .cs file Every class is in one file, all top-level, so it compiles as-is in any project that targets .NET 6 or newer.
Nullable reference types: the switch that decides whether this compiles cleanly
C# has two kinds of null, and JSON only has one. A reference type (string, List<T>, your own classes) is nullable by nature; a value type (long, bool) is not. Since C# 8 the compiler can track that difference for you — but only inside a nullable annotations context, which is why the generated file starts with #nullable enable whenever a ? is actually emitted.
- Key in every record → non-nullable.
public string Email { get; set; } = string.Empty;— dereference it freely, and the serialiser fails loudly if the API ever stops sending it. - Key missing or null → `?`.
public string? CouponCode { get; set; }orpublic long? Quantity { get; set; }. The compiler now forces a null check before use, which is the only reason the annotation is worth writing. - Initialisers keep the build green. Without them, every non-nullable reference property produces CS8618 and a project with warnings-as-errors refuses to build. The values are overwritten during deserialisation, so they cost nothing at runtime.
This is the part most converters skip. They emit public string CouponCode { get; set; } for a key that was null half the time, the project compiles with 40 warnings, and the first missing field throws a NullReferenceException three layers away from the JSON. The types here come from sampling every array element, so “optional” is a fact about your data rather than a guess.
Names: PascalCase in C#, snake_case on the wire
C# convention says CouponCode; the API says coupon_code. Both names have to survive, and System.Text.Json is case-sensitive by default — even total will not bind to Total without help. So the generator annotates every property whose exact spelling differs:
[JsonPropertyName("coupon_code")]abovepublic string CouponCode.- Keys that start with a digit get a prefix (
2fa_enabled→Field2faEnabled), because a C# identifier cannot start with a number. - Two keys that collapse onto the same C# name (
user_idanduserId) are deduplicated asUserId/UserId2, each keeping its own annotation — silently dropping one field is the alternative, and it loses data.
One file, every class top-level
C# allows many classes per file, so unlike the Java output there is no need to nest them: nested objects and array elements become sibling classes named after their path — Order → OrderCustomer → OrderItems. Arrays map to List<T> rather than T[], because that is what System.Text.Json and most C# code expect to iterate.
Integers become long, not int: 32 bits overflow on timestamps in milliseconds and on totals in cents. Narrowing a field you know is small is a safe manual edit. Floats become double, and mixed number/string fields become object — money should not be a double at all, which the precision guide explains with the decimal argument.
None of this is better than the sample it was inferred from: one record makes every key look required. The reasoning is laid out in your sample is not a schema, and it holds for C# as much as for TypeScript. For the parts specific to System.Text.Json — what required adds over #nullable enable, and why a mixed-type field becomes a JsonElement — read nullable annotations, CS8618 and JsonElement.
DevTinyTools Pro
The free generator handles the payloads most people paste by hand. Pro raises the document cap and unlocks every other tool on the site:
- 10,000,000-character documents, roughly 10 MB of JSON
- The same Pro licence unlocks every tool on the site — TypeScript, Go, Java, schemas, batch ZIP export
- Priority fixes — generation bugs move to the front of the queue
Pro is $29 one-time — a lifetime licence, sold through Lemon Squeezy as merchant of record, so VAT and sales tax are handled for you. Pro is a licence key — there is still no account. Buy DevTinyTools Pro, then activate it below and the higher limits unlock in this browser.