Skip to content
{}

JSON to C# Classes

Generate C# classes from JSON with System.Text.Json attributes and nullable types.

0 chars | 1 lines
0 chars | 0 lines

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.

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.

InputOutputNote
42intWhole number in Int32 range
9999999999longExceeds Int32
8421.5doubleFractional
trueboolBoolean
["a","b"]List<string>Uniform array
nullobject?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.

Related Tools