Embed this tool on your site
About this tool
Writing C# model classes by hand from JSON responses is slow and easy to get wrong when payloads are nested. The JSON to C# Class Generator parses a JSON sample in your browser and writes System.Text.Json-ready classes. Keys become PascalCase properties, and when the C# name differs from the JSON key a [JsonPropertyName("key")] attribute keeps the wire name. Nested objects become their own classes named after the parent and property (for example RootModelAddress), and arrays become List<T> with the element type taken from the first non-null item; mixed or empty arrays become List<object>. Numbers map to int or double, true and false to bool, strings to string and null to object. The output starts with using lines for System.Collections.Generic and System.Text.Json.Serialization. Set the root class name, click Convert and copy the result. Dates, GUIDs and large integers are not detected, so change those property types by hand where needed.
Why use it
System.Text.Json Ready: [JsonPropertyName] attributes keep the original snake_case or camelCase keys while properties follow C# PascalCase naming.
Nested Classes Generated for You: Every nested object gets its own class, named after its parent and property so names stay unique.
Typed Collections: Arrays become List<T> with the element type inferred from the data, including lists of generated classes.
Instant Validation: Invalid JSON is reported with the parser's error message before anything is generated.
Runs Locally: Parsing and code generation happen in your browser; the JSON you paste is not uploaded.
How to use
- Enter a Root Class Name (RootModel by default).
- Paste a JSON sample into JSON Input; click Beautify to format it if it is minified.
- Click Convert to generate the classes, or read the error message if the JSON is invalid.
- Review the types and change any that need it — for example string to DateTime or Guid, int to long, or double to decimal.
- Click Copy and paste the classes into your project.
When it helps
- When consuming a new REST API and needing strongly-typed response models quickly
- When a third-party webhook payload arrives and you need C# deserialization classes
- When prototyping a new feature that reads JSON configuration files
- When onboarding onto a legacy codebase that still uses raw JObject instead of typed models
- When writing integration tests and needing matching C# request/response contracts
- When you have a sample JSON response but no schema and need a first draft of the C# model
Examples
01API response with a nested object
Input{"user_id": 42, "email": "dev@example.com", "created_at": "2024-01-15T09:00:00Z", "address": {"city": "Berlin", "zip": "10115"}}
Expected result · Scroll for moreusing System.Collections.Generic;
using System.Text.Json.Serialization;
public class RootModelAddress
{
[JsonPropertyName("city")]
public string City { get; set; }
[JsonPropertyName("zip")]
public string Zip { get; set; }
}
public class RootModel
{
[JsonPropertyName("user_id")]
public int UserId { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("created_at")]
public string CreatedAt { get; set; }
[JsonPropertyName("address")]
public RootModelAddress Address { get; set; }
}
InputRoot Class Name: Order; JSON: {"order_id": 7, "order_items": [{"sku": "A1", "qty": 2, "price": 9.99}]}
Expected result · Scroll for moreusing System.Collections.Generic;
using System.Text.Json.Serialization;
public class OrderOrderItem
{
[JsonPropertyName("sku")]
public string Sku { get; set; }
[JsonPropertyName("qty")]
public int Qty { get; set; }
[JsonPropertyName("price")]
public double Price { get; set; }
}
public class Order
{
[JsonPropertyName("order_id")]
public int OrderId { get; set; }
[JsonPropertyName("order_items")]
public List<OrderOrderItem> OrderItems { get; set; }
}
Input{"trace_id": "a3f1e2d4-bc09-4c71-8e55-123456789abc", "error": null, "count": 1500000000, "ok": true}
Expected result · Scroll for moreusing System.Collections.Generic;
using System.Text.Json.Serialization;
public class RootModel
{
[JsonPropertyName("trace_id")]
public string TraceId { get; set; }
[JsonPropertyName("error")]
public object Error { get; set; }
[JsonPropertyName("count")]
public int Count { get; set; }
[JsonPropertyName("ok")]
public bool Ok { get; set; }
}
Tips
- Paste a real API response with populated values rather than an empty skeleton so the type inference engine has concrete data to analyze
- After generating, rename RootModel and generated nested class names such as RootModelAddress to meaningful domain names before committing.
- If your JSON uses snake_case keys, the [JsonPropertyName] attribute keeps the original key, so deserialization still works after properties are renamed to PascalCase.
- For financial data, manually change inferred double properties to decimal after generation to avoid floating-point precision issues
- Change properties that hold dates or UUIDs from string to DateTime or Guid after generating — the tool types them as string.
Frequently Asked Questions
Which serializer attributes does the tool emit?⌄
Only System.Text.Json's [JsonPropertyName("key")], added when the PascalCase property name differs from the JSON key. For Newtonsoft.Json, replace the attributes with [JsonProperty("key")] and the using line with using Newtonsoft.Json;.
How does the tool handle a JSON array at the root?⌄
It creates a wrapper class with the root class name and an Items property, plus a class for the array items. The Items type currently comes out as a doubly nested List<List<...>>, so change it to List<YourItem>, or deserialize the root array straight into List<YourItem> and delete the wrapper.
How are JSON numbers mapped to C# types?⌄
Whole numbers become int and numbers with a fraction become double. Values beyond int's range (about 2.1 billion) still come out as int, so switch those to long, and use decimal for money.
Are dates and GUIDs detected?⌄
No. ISO 8601 date strings and UUIDs are typed as string. Change them to DateTime, DateTimeOffset or Guid by hand; System.Text.Json reads these formats once the property type is right.
What type do null values get?⌄
object. The tool does not emit nullable reference types such as string?, so update nullable properties yourself if your project has <Nullable>enable</Nullable>.
Can I use the output directly in ASP.NET Core?⌄
Yes. The generated classes are plain C# POCOs with no framework dependencies beyond the serialization attribute namespace. They work with model binding, Swagger schema generation, and unit tests without modification.
What happens if two nested objects have the same shape?⌄
The tool generates separate classes for each unique JSON key path, so two objects named address under different parent keys will produce two class definitions. You can manually merge them into one class if the shapes are identical.
Glossary
- POCO
- Plain Old CLR Object — a simple C# class with no framework inheritance or attributes required. JSON deserialization targets are typically POCOs.
- JsonProperty
- A Newtonsoft.Json attribute that maps a C# property name to its JSON key, allowing PascalCase properties to serialize to/from camelCase or snake_case wire format.
- Nullable Reference Types
- A C# 8 feature enabled via <Nullable>enable</Nullable> that distinguishes string (non-null guaranteed) from string? (may be null) at compile time, reducing NullReferenceExceptions.
- System.Text.Json
- The built-in .NET JSON serializer introduced in .NET Core 3.0, offering better performance than Newtonsoft.Json with a slightly stricter API surface.
- Type Inference
- The process of determining a variable's or property's data type from its value rather than an explicit annotation — used here to map JSON values to appropriate C# primitive types.
- Deserialization
- Converting a JSON string into a populated C# object graph, the reverse of serialization. Requires class definitions whose properties match the JSON structure.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.
Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.
✳
✳
✓ Free to use✓ No sign-up✓ 500+ possibilities