JSON to C# Classes
Generate C# classes from JSON with System.Text.Json attributes and nullable types.
Conversion payloads stay in this browser tab and are never placed in page URLs - see how local processing works. Privacy-safe analytics record only the tool, outcome, and a coarse input-size bucket. Press Cmd/Ctrl + Enter to convert.
How to Generate C# Classes from JSON
Paste a representative API response and the generator walks it, creating one class per distinct object shape and naming nested classes after their parent and key so two different "metadata" objects do not collide. Copy the result into your project and adjust nullability and numeric widths to match the documented contract rather than the single sample.
Type Mapping
How each JSON type is inferred.
| Input | Output | Note |
|---|---|---|
| 42 | int | Whole number in Int32 range |
| 9999999999 | long | Exceeds Int32 |
| 8421.5 | double | Fractional |
| true | bool | Boolean |
| ["a","b"] | List<string> | Uniform array |
| null | object? | Type unknown from sample |
One Sample Is Not a Schema
Generated classes describe the payload you pasted. Optional fields that happen to be present, arrays that happen to be uniform, and integers that happen to be small all become firm decisions in the output. Where the API has a published schema, treat the generated code as a starting point and reconcile it against that document before relying on it in production.
Frequently Asked Questions
Which serializer do the generated classes target?
System.Text.Json, the built-in serializer since .NET Core 3.0. Each property carries a [JsonPropertyName("...")] attribute holding the original JSON key, so PascalCase C# names round-trip correctly against camelCase or snake_case payloads.
How are numeric types chosen?
Whole numbers within Int32 range become int, larger whole numbers become long, and any value with a fractional part becomes double. Review these against your API contract - a single sample cannot prove that a field is always an integer.
How is null represented?
A JSON null becomes object? rather than a guessed type, because a null sample carries no type information. Replace it with the nullable type your API documents, such as DateTime? or string?.
What about arrays of objects?
An array root generates a RootItem class from the first element with a comment showing that you deserialize into List<RootItem>. Nested arrays become List<T> properties.