JSON to C# Classes Converter

Paste JSON to generate C# classes, records, or annotated models. 100% client-side.

JSON Input
C# Output
Paste JSON above to generate C# classes.

How to Convert JSON to C# Classes

  1. Paste your JSON into the input area on the left.
  2. Choose a mode — Class (mutable properties), Record (immutable C# 9+), or JsonProperty (Newtonsoft.Json attributes).
  3. Copy or download the generated C# code using the buttons above the output.
  4. 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 with System.Text.Json in .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., JSON user_name to C# UserName). Requires using Newtonsoft.Json or Install-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.

Frequently Asked Questions

With .NET's built-in System.Text.Json: var obj = JsonSerializer.Deserialize<RootObject>(jsonString). With Newtonsoft.Json: var obj = JsonConvert.DeserializeObject<RootObject>(jsonString). Both approaches require a C# class that matches the JSON structure. This tool generates that class for you automatically.
C# classes with auto-properties ({get; set;}) are mutable and widely compatible with all serializers. C# records (introduced in C# 9) are immutable by default, support value-based equality, and have a concise positional syntax. For JSON deserialization with System.Text.Json, records work well using the constructor-based approach. Use records when you want immutable data transfer objects.
No. This converter runs entirely in your browser using JavaScript. Your JSON never leaves your machine. There is no server processing, no logging, and no data collection.
JsonProperty attributes (from Newtonsoft.Json) or JsonPropertyName attributes (from System.Text.Json) tell the serializer which JSON key maps to which C# property. This is needed when the JSON uses camelCase or snake_case keys but your C# class follows PascalCase conventions. The attribute mode in this tool adds [JsonProperty("key")] to every property.
JSON null values are mapped to nullable C# types using the ? suffix (e.g., string?, int?). In Class mode, reference types like string are nullable by default in .NET 6+ with nullable reference types enabled. Value types (int, double, bool) get the ? suffix to allow null. This matches the JSON contract where any field can be null.