JSON to C# Class

Generate C# classes with System.Text.Json or Newtonsoft.Json attributes from any JSON object.

What is C# JSON Serialization?

In C#, JSON serialization converts between C# objects (classes, records, structs) and JSON strings. The .NET ecosystem has two main serializers: System.Text.Json (built-in since .NET Core 3.0, preferred for new projects) and Newtonsoft.Json (the classic library, still dominant in older codebases).

When consuming REST APIs in ASP.NET Core or calling external services, you typically define C# model classes that match the JSON structure. The serializer handles conversion automatically when you use JsonSerializer.Deserialize<T>() or HttpClient.GetFromJsonAsync<T>(). This tool generates the complete class hierarchy from your JSON instantly.

System.Text.Json vs Newtonsoft.Json

FeatureSystem.Text.JsonNewtonsoft.Json
Attribute[JsonPropertyName][JsonProperty]
PackageBuilt into .NET 3+Newtonsoft.Json NuGet
PerformanceFaster (span-based)Slower but more flexible
Null handlingExplicit nullableMore lenient
Best for.NET 6+ / ASP.NET CoreLegacy / complex scenarios

Example: System.Text.Json Output

csharp
using System.Text.Json.Serialization;
using System.Collections.Generic;

public class Address
{
    [JsonPropertyName("street")]
    public string Street { get; set; }

    [JsonPropertyName("city")]
    public string City { get; set; }
}

public class Root
{
    [JsonPropertyName("id")]
    public long Id { get; set; }

    [JsonPropertyName("name")]
    public string Name { get; set; }

    [JsonPropertyName("address")]
    public Address Address { get; set; }
}

Deserialize with System.Text.Json

csharp
using System.Text.Json;

var root = JsonSerializer.Deserialize<Root>(jsonString);
// Or with options:
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var root2 = JsonSerializer.Deserialize<Root>(jsonString, options);

Type Mapping

JSON TypeC# TypeNotes
stringstringNullable reference type
integerlongAvoids int overflow
floatdoubleDouble precision
booleanboolNon-nullable
nullobject?Nullable object
arrayList<T>System.Collections.Generic
objectclassNew named C# class

Frequently Asked Questions

Use System.Text.Json for all new .NET 6+ projects. It's built-in, faster, and the default for ASP.NET Core minimal APIs and controllers.

Use JsonSerializer.Deserialize<List<Root>>(jsonString) where Root is your generated class. The List<T> property types are generated automatically.

For System.Text.Json — no, it's included in .NET 3+. For Newtonsoft.Json — install Newtonsoft.Json from NuGet.

Each property gets a [JsonPropertyName] or [JsonProperty] attribute with the original name. No configuration needed.

Yes — the generated classes are plain C# POCOs. You can use them as EF entity classes by adding navigation properties and [Key] attributes.

Related Tools