JSON to C# Class Converter
This JSON to C# converter turns a sample payload into classes of auto-properties, each carrying a [JsonPropertyName] attribute with the original key so System.Text.Json maps it correctly. Fields that are optional, or that were null somewhere in the sample, are emitted as nullable types — with nullable reference types enabled, the compiler then points at exactly the places that need to handle an absent value rather than leaving it to be found at runtime. A namespace can be declared, and the whole output is ready to paste into a single file.
How it works
Paste a representative JSON sample and the C# declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.
Each object becomes a class of auto-properties with a [JsonPropertyName] attribute carrying the original key, ready for System.Text.Json.
Fields that are optional or were null somewhere in the sample are emitted as nullable types, so the compiler tells you where to handle the absence.
Generation runs entirely in your browser — nothing you paste is uploaded.
How to convert JSON to C# classes
- Paste a representative JSON payload into the input on the left.
- Set a namespace if you want one declared.
- Copy the generated classes into your project.
Built for System.Text.Json
Each property carries a [JsonPropertyName] attribute with the original key, which is what the
built-in serialiser reads. If your project uses Newtonsoft.Json instead, replace the attribute with
[JsonProperty] — the class shapes are otherwise identical.
Nullable where the data allows it
Fields that are optional, or that were null somewhere in your sample, are emitted as nullable types. With nullable reference types enabled, the compiler will then point at exactly the places you need to handle an absent value, rather than leaving it to be discovered at runtime.
Give it a representative sample
The types are inferred from the data you paste, so the quality of the output depends on how complete your example is. Two things are worth including: an array with more than one element, so fields that appear in some records but not others get marked optional rather than assumed mandatory; and real values rather than placeholders, so numbers are recognised as numbers and whole numbers are told apart from decimals.
What inference cannot tell you
A sample shows what the data was, not what it can be. A field that happened to be null in every record you pasted has no discoverable type, and an enum looks exactly like a string. Treat the generated classes as a first draft that saves the typing, then tighten the parts you know more about than the sample does.
Frequently asked questions
Which serialiser are the classes built for?
System.Text.Json, the one built into .NET — each property carries a [JsonPropertyName] attribute. For Newtonsoft.Json, swap it for [JsonProperty]; the class shapes are otherwise identical.
Why are some properties nullable?
Because they were optional or null in the sample. Marking them nullable lets the compiler flag every place that has to handle the absence, instead of leaving it to surface as a runtime exception.
Can I set a namespace?
Yes. Enter one and a file-scoped namespace declaration is added above the classes.
What number types are used?
Whole numbers become long and decimals become double. Change them to int or decimal by hand where you know the real range — money in particular usually wants decimal rather than double.
Is my data sent to a server?
No. Everything is generated in your browser.
Related tools
JSON to Java Class Converter
This JSON to Java converter generates POJOs with Jackson annotations, getters and setters.
JSON to TypeScript Converter
This JSON to TypeScript converter turns a sample payload into exported interfaces.
JSON to JSON Schema Generator
This JSON to JSON Schema generator produces a draft 2020-12 schema from a sample payload.