How to use the JSON to C# generator
- Paste a JSON object, or an array of objects, such as an API response.
- Set the name for the root class and choose classes or records.
- Press Convert, then copy or download the code into your project.
Everything runs in your browser. Nothing you type is sent to our servers. Your last input is remembered in this browser only.
How types are chosen
Every object in an array is checked, not just the first, so the generated class has every field that appears in any item. A field that is missing from some items, or is null in some, becomes nullable. Each property gets a [JsonPropertyName] attribute with the original key, so snake_case or kebab-case keys still map to PascalCase property names.
| JSON value | C# type |
|---|---|
| "text" | string |
| 42 | int |
| 3000000000 | long (too big for int) |
| 9.99 | double |
| true | bool |
| { ... } | a new class named after the key |
| [ ... ] | List<T>; "orders" becomes List<Order> |
| null only, or mixed types | object |
Using the classes
The code targets System.Text.Json, built into .NET Core 3.0 and later. If your project uses Newtonsoft.Json, replace [JsonPropertyName("x")] with [JsonProperty("x")] and the using line with Newtonsoft.Json.
Dates in JSON are just strings, so they are generated as string. If you change a property to DateTime or DateTimeOffset, System.Text.Json will parse ISO 8601 dates such as 2026-03-01T10:00:00Z for you. Use decimal rather than double for money.
using System.Text.Json;
var order = JsonSerializer.Deserialize<Root>(json);
var list = JsonSerializer.Deserialize<List<Root>>(jsonArray);When you would use it
- Creating models for a third-party API from a sample response.
- Writing DTOs for a new ASP.NET Core endpoint from the JSON you agreed with the front end.
- Getting a quick, accurate starting point instead of typing out a large nested model.
Frequently asked questions
Classes or records?
Records are shorter and immutable, and are a good fit for data you only read, such as API responses. Classes with get and set are easier when you build or change the object step by step.
Why are some properties nullable?
Because in your sample they were null or missing in at least one item. If your API guarantees a value, remove the question mark. A single sample cannot prove a field is always present, so check against the API's documentation.
Why is a number typed as int when it can have decimals?
The type comes from the sample. If every sample value is a whole number, it becomes int. Add an example with decimals, or change it to double or decimal by hand.
Can it read JSON with comments or trailing commas?
No, the input must be valid JSON. Run it through the JSON Formatter's Repair first.