JSON to C# Classes Converter
Paste JSON to generate C# classes, records, or annotated models. 100% client-side.
How to Convert JSON to C# Classes
- Paste your JSON into the input area on the left.
- Choose a mode — Class (mutable properties), Record (immutable C# 9+), or JsonProperty (Newtonsoft.Json attributes).
- Copy or download the generated C# code using the buttons above the output.
- Paste into Visual Studio or Rider and use with
JsonSerializer.Deserialize<RootObject>(json).
Understanding C# JSON Serialization
C# has two major JSON libraries: System.Text.Json (built into .NET Core 3.0+ and .NET 5+) and Newtonsoft.Json (also called Json.NET). The Class and Record modes generate code that works with either library. The JsonProperty mode generates [JsonProperty] attributes specifically for Newtonsoft.Json, which is the most common JSON library in the .NET ecosystem and is the default in ASP.NET Core projects pre-.NET 5.
Output Modes Explained
- Class — Standard C# class with
public Type PropertyName { get; set; }auto-properties. Compatible with all .NET JSON serializers. Mutable, so properties can be changed after construction. The most common pattern for API models in ASP.NET Core. - Record — C# 9+ record type using
public record RootObject(...)positional syntax. Records are immutable, support value-based equality, and have a compact declaration. Works withSystem.Text.Jsonin .NET 6+ and with the constructor-based deserialization approach. - JsonProperty — Class mode with
[JsonProperty("key")]attributes from Newtonsoft.Json. Use this when you need to map JSON keys that differ from C# property names (e.g., JSONuser_nameto C#UserName). Requiresusing Newtonsoft.JsonorInstall-Package Newtonsoft.Json.
C# Type Mapping from JSON
- JSON string →
string - JSON integer →
int - JSON float →
double - JSON boolean →
bool - JSON null → nullable type (
string?,int?) - JSON array of strings →
List<string> - JSON array of objects →
List<ChildClass> - JSON nested object → separate class definition
Using the Generated Classes with ASP.NET Core
In ASP.NET Core, generated classes work directly as controller action parameters, which are automatically deserialized from the request body. Decorate your action with [HttpPost] and accept the type as a parameter: public IActionResult Create([FromBody] RootObject data). ASP.NET Core's model binding pipeline handles deserialization. For response serialization, return the object from your action and the framework serializes it to JSON automatically.
Nullable Reference Types (.NET 6+)
In .NET 6 and later projects, nullable reference types (NRT) are enabled by default in new project templates (<Nullable>enable</Nullable> in .csproj). With NRT enabled, a string property cannot be null without a warning — you must declare it as string? if it can be null. This converter generates ? on properties that were null in your example JSON, and uses non-nullable types for properties that had values. Review the output to ensure nullability reflects your actual API contract.
System.Text.Json vs. Newtonsoft.Json
System.Text.Json is faster, allocates less memory, and requires no external package in .NET 5+. It is the default for new ASP.NET Core projects. Its limitations include no support for some advanced scenarios (circular references, dynamic objects, BSON). Newtonsoft.Json is the industry standard, has been battle-tested since 2007, and has a richer feature set. For most new projects, System.Text.Json is the right choice. If you need Newtonsoft.Json, use the JsonProperty mode from this tool. For System.Text.Json, use [JsonPropertyName("key")] (the attribute name differs but the concept is the same). Related: try our JSON Formatter to validate your JSON before converting.