JSON to C# class generator

Paste a JSON response and get C# types to deserialize it. Choose classes with get/set properties or positional records, and keep [JsonPropertyName] attributes on so the PascalCase properties map to the exact JSON keys with System.Text.Json.

Generate

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste a JSON sample. Use a realistic one: the more items an array holds, the better optional keys are detected.
  2. Choose classes or records, and whether to add [JsonPropertyName] attributes.
  3. Copy the code into a .cs file. The top-level type is Root; rename it to suit your domain.

How it works

The sample is read into a shape: each key with every type seen there. All objects of one array are merged into one class, so a key present in only some of them becomes nullable.

  • Property names are PascalCase built from the key: order_id → OrderId, first-name → FirstName, 2fa → N2fa.
  • A property may not share its class’s name, so a key item inside class Item becomes ItemValue.
  • Class names come from keys too: items holds a List, customer becomes Customer. Root comes first, nested classes after it.
  • With a top-level array, a comment names the type to deserialize, such as List.

Worked example

{"items":[{"sku":"A","note":null,"qty":1},{"sku":"B","note":"x"}]} as classes without attributes gives:

using System.Collections.Generic;

public class Root
{
    public List<Item> Items { get; set; } = new();
}

public class Item
{
    public string Sku { get; set; } = "";
    public string? Note { get; set; }
    public long? Qty { get; set; }
}

note is null once, so it is string?. qty is missing from the second item, so it is long?.

Tips

  • Check numbers the sample got lucky with: a price of 24 in every item gives long, though real data may hold 24.99.
  • Deserialize with JsonSerializer.Deserialize<Root>(json); for a top-level array use the type named in the comment.
  • For other languages, see JSON to Java, JSON to TypeScript and JSON to Go.

Frequently asked questions

How are JSON types mapped to C#?

Strings become string, true and false bool, whole numbers long and other numbers double (a mix of both becomes double). Arrays become List<T>, objects become their own classes, and a place holding different kinds of values becomes object?.

When is a property nullable?

When the sample has null there, or when the key is missing from some objects of an array. Value types get ? (long?, bool?), reference types too (string?, List<T>?), which matches nullable reference types, on by default in new .NET projects.

Why are there initializers like = "" and = new()?

In a class, a non-nullable string, list or nested object must not be left null, or the compiler warns (CS8618). The generator starts strings as an empty string and lists and objects as new().

Do I need the attributes?

System.Text.Json matches names case-sensitively by default, so the property OrderId does not match the key order_id. [JsonPropertyName("order_id")] makes the match explicit. Without the attributes, set PropertyNamingPolicy or PropertyNameCaseInsensitive in JsonSerializerOptions instead.

Which C# version is needed?

Records and new() need C# 9 (.NET 5) or newer; nullable annotations need C# 8. Positional records deserialize through their constructor with System.Text.Json.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.