Paste JSON and get C# classes with typed properties and serializer attributes as you type.
Paste JSON, upload a .json file or drop one here.
Updates as you type. Copy it or download a Models.cs file.
Converting…
This free JSON to C# class converter reads a sample JSON document and writes the C# classes that describe it. Paste an API response, a config file or a webhook payload, and you get a ready-to-use Root class plus a separate class for every nested object, with typed properties you can drop straight into your project. Nothing is installed or uploaded: the classes are generated in your browser.
It saves the tedious part of calling a JSON API from .NET. Instead of typing out dozens of properties and guessing their types, you paste the response once and deserialize it into a strongly typed object with a single line of code. The output is plain C# with no helper code, so it works in ASP.NET Core, console apps, Blazor and .NET MAUI alike.
.json file or drag one onto the editor.Root) and the Namespace you want the classes to live in.System.Text.Json or Newtonsoft.Json. The attributes on each property change to match.Models.cs file.Here is a small order document and the classes the converter produces from it with the default options. Snake_case keys become PascalCase properties, each nested object gets its own class, the array becomes a List<Item>, and the ISO timestamp becomes a DateTimeOffset.
{
"id": 1042,
"order_number": "A-1042",
"total": 59.9,
"created_at": "2025-03-14T09:30:00Z",
"customer": {
"first_name": "Ada",
"phone": null
},
"items": [
{ "sku": "KB-01", "quantity": 2 },
{ "sku": "MS-07", "quantity": 1, "note": "Fragile" }
]
}namespace MyApp.Models
{
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
public partial class Root
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("order_number")]
public string OrderNumber { get; set; }
[JsonPropertyName("total")]
public double Total { get; set; }
[JsonPropertyName("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonPropertyName("customer")]
public Customer Customer { get; set; }
[JsonPropertyName("items")]
public List<Item> Items { get; set; }
}
public partial class Customer
{
[JsonPropertyName("first_name")]
public string FirstName { get; set; }
[JsonPropertyName("phone")]
public object Phone { get; set; }
}
public partial class Item
{
[JsonPropertyName("sku")]
public string Sku { get; set; }
[JsonPropertyName("quantity")]
public long Quantity { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("note")]
public string? Note { get; set; }
}
}| JSON | C# type | Notes |
|---|---|---|
| string | string | Strings that look like ISO 8601 dates or date-times become DateTimeOffset. |
| whole number | long | Holds any integer an API is likely to return. Change it to int by hand if you know it stays small. |
| decimal number | double | An array that mixes whole and decimal numbers becomes List<double>. |
true / false | bool | Always a plain bool. |
null | object | A value that is only ever null gives the converter nothing to infer a type from. |
{ } object | A new class | Named after the property that holds it. The root uses the class name option. |
[ ] array | List<T> | T is the element type, or a class for an array of objects. |
C# properties are PascalCase by convention, while JSON keys are usually camelCase or snake_case. The converter renames each property to PascalCase (first_name becomes FirstName, order-id becomes OrderId) and adds an attribute holding the exact JSON key: [JsonPropertyName("first_name")] for System.Text.Json or [JsonProperty("first_name")] for Newtonsoft.Json. That matters because System.Text.Json matches property names case-sensitively by default, so a PascalCase property would otherwise stay empty.
Keys that are not valid C# identifiers are cleaned up the same way. A key such as 2fa becomes The2Fa, and the attribute still points at the original key. On .NET 8 and later you can skip the attributes and set PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower instead, if all your keys use snake_case.
The converter looks at every object in an array. A property that is missing or null in some items but present in others becomes nullable: string?, long? and so on. The note property in the example above works this way. With System.Text.Json these properties also get JsonIgnoreCondition.WhenWritingNull, so they are left out when you serialize a null.
Properties that were always present are not marked as nullable. If your project enables <Nullable>enable</Nullable>, the compiler warns (CS8618) that those properties are uninitialized when the class is constructed. Add the required modifier on C# 11 and later, give them a default such as = string.Empty;, or add ? where the API may omit the value.
The converter only sees the sample you paste, so it infers types from that one document. A decimal written as 1.0 is read as the whole number 1 by the JSON parser and therefore becomes long; use a value such as 1.5 in your sample if the field is really a decimal. Date-only strings like 2025-03-14 also become DateTimeOffset; change the type to DateOnly if you prefer. An array that mixes types, such as [1, "a"], produces a helper struct for the union, which is rarely what you want, so it is usually better to fix the data.
Once the classes are in your project, a single call turns JSON text into a C# object. If the JSON document is an array, deserialize to List<Root> instead of Root.
using System.Text.Json;
using MyApp.Models;
string json = File.ReadAllText("order.json");
Root? order = JsonSerializer.Deserialize<Root>(json);
Console.WriteLine(order?.Customer.FirstName); // Ada
// Back to JSON; "note" is left out when it is null
string output = JsonSerializer.Serialize(order);using Newtonsoft.Json;
using MyApp.Models;
string json = File.ReadAllText("order.json");
Root? order = JsonConvert.DeserializeObject<Root>(json);
Console.WriteLine(order?.Customer.FirstName); // Ada
string output = JsonConvert.SerializeObject(order);Visual Studio has the same idea built in: copy JSON, open a .cs file and choose Edit > Paste Special > Paste JSON as Classes. It is convenient inside the IDE, but it keeps the JSON keys as property names, so snake_case ends up in your C# code, and it offers no options for the root class name, namespace or serializer. This online tool works in any browser, on any machine, and produces idiomatic names with attributes that keep the mapping intact.
Working in another language? The same approach is available as a JSON to TypeScript converter, a JSON to Java converter and a JSON to Go converter. Need a realistic payload to test with? Create one with the JSON Generator, and if you would rather validate documents than generate classes, build a contract with the JSON Schema generator.
Paste your JSON into the JSON Input editor, or upload a .json file. The C# classes appear in the output editor as you type. Set the class name, namespace and serializer, then copy the code or download it as Models.cs.
Choose the library your project already uses. System.Text.Json ships with modern .NET and gets [JsonPropertyName] attributes; Newtonsoft.Json is a NuGet package and gets [JsonProperty] attributes. The classes are otherwise identical.
With System.Text.Json call JsonSerializer.Deserialize<Root>(json). With Newtonsoft.Json call JsonConvert.DeserializeObject<Root>(json). Replace Root with the class name you chose, or use List<Root> when the JSON is an array.
A sample can't tell the converter how large a number may get, and a JSON integer can exceed the range of int. long holds any whole number a typical API returns, and you can change a property to int by hand when you know the range is small.
A property that is only ever null in your sample has no type to infer, so it becomes object. If the same property has a value in one array item and is null or missing in another, it becomes a nullable type such as string? or long?.
Paste JSON as Classes needs Visual Studio and keeps the JSON names as C# property names. This converter works in any browser, gives you PascalCase properties, and adds attributes so they still map to the original JSON names.
No. The classes are generated entirely in your browser, so your JSON never leaves your device. It is safe to use with real API responses and internal payloads.