JSON to C# Class Converter
Paste a representative JSON object or array and generate dependency-free C# models with nested sealed classes and List<T> properties. Your sample stays in the browser.
How to use it
- Paste a valid, representative JSON object or array, or select Load Example.
- Choose a valid root class name such as
UserResponse. - Select Generate C# or press Ctrl/⌘ + Enter.
- Copy or download the result, then compare every inferred type with the real API contract.
JSON to C# example
A typical API response contains scalar values, arrays, nested objects, and occasionally null:
{
"id": 42,
"name": "Ada",
"active": true,
"roles": ["admin", "editor"],
"address": {"city": "London", "postal_code": "SW1A"}
}
The converter creates a sealed root model, a nested sealed Address class, value-type properties for booleans and numbers, and List<string> for the homogeneous roles array. Nested models remain inside the root type so the complete result can be copied into one source file.
C# type inference rules
JSON strings become string, booleans become bool, integers become long, and decimal numbers become double. Homogeneous arrays become List<T>. Empty and mixed arrays fall back to List<object>, because the sample does not prove one narrower element type.
A JSON null value becomes object?. The generated file enables nullable reference types with #nullable enable. This fallback is deliberately conservative: a single null cannot reveal whether the real value is a nullable string, number, collection, or custom object. Replace it with the contract’s actual type before production use.
Properties and JSON name mapping
JSON keys are converted into C#-compatible PascalCase property names. Keys beginning with a number are made safe, and punctuation such as underscores or hyphens is removed during conversion. When a generated property name differs from its JSON key, an inline comment preserves the original name for review.
The output does not depend on a serializer. Modern .NET applications often use System.Text.Json, while some projects use Newtonsoft.Json. Add the serializer’s property-name attribute when an API key cannot be handled by the configured naming policy. Keeping those attributes out of the initial model avoids forcing a package or configuration choice on every project.
Initial values and nullability
Generated strings start with string.Empty; lists and nested models use target-typed new(). This keeps nullable-reference warnings useful without guessing that the payload always includes a field. Numeric and boolean properties keep their normal default values. If absence and zero must be distinguishable, change them to nullable value types such as long? or bool?.
Single-sample limitations
Inference only sees the values in the pasted document. It cannot discover optional properties, polymorphic response shapes, enums, date formats, UUID semantics, or whether an integer identifier should actually be stored as a string. Arrays with different object shapes are also reduced to a broad element type. Generate a starting model, then compare it with the OpenAPI or JSON Schema contract and representative production samples.
Security and privacy
Conversion runs entirely in the current browser tab. Cryonel does not upload the JSON sample or generated C# source. Generated models can still reveal private field names if they are shared publicly, so remove sensitive payload details from tickets, source snippets, and chat messages.
Frequently Asked Questions
Does the generated C# class deserialize JSON automatically?
No. It provides a dependency-free model shape. Add System.Text.Json or Newtonsoft.Json attributes when your application needs explicit name mapping.
How are JSON arrays converted to C#?
Homogeneous arrays become List<T>. Empty or mixed-type arrays become List<object> because one sample cannot prove a narrower safe type.
What type is generated for JSON null?
Null becomes object? because the sample does not reveal the value's intended non-null type.