JSON to C# Class

JSON Tools

How to use the JSON to C# Class

Generate C# classes in seconds:

1

Paste your JSON

Paste any JSON object into the input panel. Arrays of objects are also accepted — the first element is used for type inference.

2

Choose serializer

Select Newtonsoft.Json for [JsonProperty] attributes, or System.Text.Json (built into .NET 5+) for [JsonPropertyName] attributes.

3

Set class name

Enter the root class name in PascalCase (e.g. User, Product). Nested objects automatically generate their own named classes.

4

Copy into Visual Studio

Paste the class definitions into your C# project. All using statements, namespace, and nullable annotations are included and ready to compile.


When to use this tool

Use this when building .NET applications that consume JSON APIs:

  • Building an ASP.NET Core API and need request/response model classes from JSON examples
  • Consuming a third-party REST API in a .NET application and need strongly-typed models
  • Adding strongly-typed models to a C# project that currently uses dynamic or JObject
  • Generating C# DTOs from API documentation JSON samples
  • Scaffolding Blazor data models from a JSON API response shape

Frequently asked questions

Q:Which JSON serializers are supported?
Both Newtonsoft.Json (the most widely used .NET JSON library, required for .NET Framework and older .NET Core) and System.Text.Json (the built-in serializer in .NET 5+) are supported with correct attribute syntax for each. Switch between them instantly using the toolbar toggle.
Q:How are nullable types handled?
JSON null values generate nullable C# types using C# 8+ nullable reference type syntax — string?, int?, bool?, and so on. The generated classes are drop-in compatible with projects that have nullable reference types enabled (#nullable enable).
Q:Are nested objects supported?
Yes — nested JSON objects generate separate public class definitions that appear above the root class in the output, following standard .NET convention. The parent class references them by name with the correct type.
Q:How are arrays handled in C#?
JSON arrays become List<T> typed properties. Arrays of primitives become List<string>, List<int>, List<double> etc. Arrays of objects generate a named nested class and type the property as List<NestedClass>. The using System.Collections.Generic import is included automatically.
Q:How do I deserialize with the generated classes?
For System.Text.Json use JsonSerializer.Deserialize<YourClass>(json). For Newtonsoft.Json use JsonConvert.DeserializeObject<YourClass>(json). The info banner below the output shows the exact snippet for whichever serializer you have selected.