JSON to C# Class

Generate C# classes from JSON with [JsonPropertyName] attributes for the modern System.Text.Json serializer. For Newtonsoft.Json, swap to [JsonProperty] and add using Newtonsoft.Json;.

How to use the JSON to C# Class

Paste JSON. Output uses System.Text.Json (the default in modern .NET 6+). For records, you can collapse the property syntax to public record Response(string Id, string Name); manually.

Generating C# classes from JSON

When you consume an API in C# you want strongly-typed classes, not JsonElement lookups and string keys scattered through your code. But hand-writing those classes from a sample response — getting every property name, type, and serializer attribute right — is dull and easy to get subtly wrong.

This generates C# classes from a JSON sample, annotated with [JsonPropertyName] for the modern System.Text.Json serializer that ships with .NET 6 and later, nesting a class for each nested object. If your project still uses Newtonsoft.Json, switch the attributes to [JsonProperty]; for the equivalent on other platforms, the Java, Go, and Rust generators follow the same idea.

Common use cases

  • Type an API client — turn a sample response into C# model classes.
  • System.Text.Json — get [JsonPropertyName] attributes for the modern serializer.
  • Nested models — generate a class per nested object automatically.
  • Scaffold DTOs — create data-transfer objects without a schema.
  • Records — start from generated classes and collapse to a record where it fits.

Frequently asked questions

Which serializer does it target?

System.Text.Json, the default in .NET 6 and later, using [JsonPropertyName] attributes.

What about Newtonsoft.Json?

Swap [JsonPropertyName] for [JsonProperty] and add a using for Newtonsoft.Json; the class structure is the same.

Are nested objects handled?

Yes — each nested object becomes its own class, referenced from the parent property.

Can I get records instead of classes?

The output is classes by design; you can collapse a class to a positional record by hand where that style suits.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: