JSON to C# Class Generator
Paste JSON and get C# classes or records with nested types, List<T>, nullable types and System.Text.Json or Newtonsoft attributes. Runs in your browser, so your data is never uploaded.
JSON Input
C#
What Is a JSON to C# Converter?
A JSON to C# converter reads example JSON, like an API response, and writes C# classes that match it, with the right types, nested classes and lists. You paste the result into your project and deserialize the JSON with System.Text.Json or Newtonsoft.Json, instead of typing every property by hand.
How to Convert JSON to C# Classes
- Paste a sample of your JSON, or drop a .json file on the box.
- Choose a class name, classes or records, and System.Text.Json or Newtonsoft attributes.
- Click Generate C#, or press Ctrl + Enter.
- Copy the code, or download it as a .cs file.
Example
{
"order_id": "A-2045",
"created_at": "2026-11-15T09:30:00Z",
"is_paid": true,
"total": 89.97,
"discount": null,
"customer": {
"name": "James Smith",
"email": "james@example.com"
},
"items": [
{
"sku": "KB-01",
"quantity": 1,
"price": 59.99
},
{
"sku": "MS-02",
"quantity": 2,
"price": 14.99,
"gift_wrap": true
}
]
}using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Order
{
[JsonPropertyName("order_id")]
public string OrderId { get; set; } = "";
[JsonPropertyName("created_at")]
public string CreatedAt { get; set; } = "";
[JsonPropertyName("is_paid")]
public bool IsPaid { get; set; }
[JsonPropertyName("total")]
public double Total { get; set; }
[JsonPropertyName("discount")]
public object? Discount { get; set; }
[JsonPropertyName("customer")]
public Customer Customer { get; set; } = new();
[JsonPropertyName("items")]
public List<Item> Items { get; set; } = new();
}
public class Customer
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("email")]
public string Email { get; set; } = "";
}
public class Item
{
[JsonPropertyName("sku")]
public string Sku { get; set; } = "";
[JsonPropertyName("quantity")]
public long Quantity { get; set; }
[JsonPropertyName("price")]
public double Price { get; set; }
[JsonPropertyName("gift_wrap")]
public bool? GiftWrap { get; set; }
}The nested customer object becomes its own Customer class, the items array becomes List<Item>, and gift_wrap is bool? because only one item has it. created_at stays a string: change it to DateTimeOffset to get a real date (see the tips below).
How the Types Are Chosen
| JSON value | C# type |
|---|---|
| Text | string |
| Whole number | long, so large IDs never overflow |
| Number with decimals | double. Use decimal for money if you need exact sums. |
| true / false | bool |
| Object | Its own class, like Address |
| Array | List<T>, like List<Order> |
| Missing in some items, or null | A nullable type, like string? or long? |
| Only null, or mixed types | object?. Replace it with the real type if you know it. |
Required strings, lists and objects get a default value (= "" or = new()), so the code compiles without nullable warnings in projects that have nullable reference types turned on.
Deserialize JSON in C#
using System.Text.Json;
string json = File.ReadAllText("order.json");
Order? order = JsonSerializer.Deserialize<Order>(json);
Console.WriteLine(order?.Customer.Name); // James SmithSystem.Text.Json matches property names case-sensitively by default, which is why the generator adds [JsonPropertyName] to every renamed property. If you turn attributes off, pass new JsonSerializerOptions(JsonSerializerDefaults.Web) to match names like firstName to FirstName. Note that it still will not match first_name; for snake_case keys, keep the attributes.
// dotnet add package Newtonsoft.Json using Newtonsoft.Json; Order? order = JsonConvert.DeserializeObject<Order>(json);
If the JSON is an array at the top level, deserialize it as List<Order>.
Classes or Records?
- Classes work everywhere, including older .NET Framework projects, and let you change values after loading.
- Records (C# 9 / .NET 5 and newer) are short and immutable, which suits API responses you only read. System.Text.Json fills them through their constructor.
Tips
- Dates: date strings stay
string. If they are ISO 8601, like2026-11-15T09:30:00Z, change the type toDateTimeorDateTimeOffsetand both libraries parse them for you. - Use a complete sample. The generator only sees the fields in your example. Include an item with every optional field if you can.
- Check the JSON first. Broken JSON stops deserialization with a JsonException. Fix it with JSON Repair or check it in the JSON Validator.
Your JSON never leaves your browser, so it is safe to paste real API responses. Need another language? Try JSON to Go, JSON to Java, JSON to TypeScript or JSON to PHP.
Frequently Asked Questions
How do I convert JSON to C# classes?
Paste a sample of your JSON into the converter and click Generate C#. It writes classes or records with nested types, List<T> and System.Text.Json or Newtonsoft.Json attributes.
Should I use System.Text.Json or Newtonsoft.Json?
System.Text.Json is built into .NET Core 3.0 and newer and is fast and the default for new projects. Newtonsoft.Json is older, very flexible and common in existing and .NET Framework projects. The converter supports both.
Why does every property have a JsonPropertyName attribute?
System.Text.Json matches names case-sensitively by default, so a key like first_name only maps to a FirstName property when the attribute says so.
Is my JSON uploaded?
No. The C# code is generated in your browser and your JSON never leaves your device.