JSON to C# Class Converter
Generate C# model classes from a JSON sample, with nested classes and List<T> properties created automatically.
Input JSON
Paste your JSON or upload a JSON file.
Generated Output
Your converted code will appear here.
About the JSON to C# Class Converter
Generate C# model classes from a JSON sample, with nested classes and List<T> properties created automatically.
When you consume a REST API from .NET, you usually need a class that matches the JSON so System.Text.Json or Newtonsoft.Json can deserialize it. Writing those classes by hand is slow and error-prone for large payloads. This converter reads a sample JSON document and generates a public C# class with an auto-property for every key. Nested objects become their own classes, and arrays become List<T> properties.
How to use it
- Paste a JSON sample into the input editor or upload a
.jsonfile. - Select Convert.
- Review the output, then copy it or download it.
How JSON types are mapped
| JSON value | Generated as |
|---|---|
| string | string |
| whole number (42) | int |
| decimal number (9.99) | decimal |
| true / false | bool |
| nested object | a new class named after the key |
| array | List<T> (T taken from the first element) |
| null | object |
Example
This input:
{
"id": 1,
"name": "Ada",
"price": 9.99,
"active": true,
"tags": ["new", "sale"],
"address": { "city": "London", "zip": "N1" }
}
produces this output:
public class Root
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public bool Active { get; set; }
public List<string> Tags { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string City { get; set; }
public string Zip { get; set; }
}
Limitations and things to review
The generated code is a starting point. Review it before using it:
- Property names are created by upper-casing the first letter of the JSON key. Keys such as "first-name" or "2fa" are not valid C# identifiers and must be renamed. Add [JsonPropertyName("first-name")] to keep the mapping.
- Whole numbers become int. Use long for IDs or counters that can exceed 2,147,483,647.
- Values that are null in the sample become object. Replace them with the real type, such as string? or int?.
- For arrays, only the first element is inspected. If later elements have extra properties, add them manually.
- Two nested objects with the same key name produce two classes with the same name. Rename one of them.
- The output doesn't include using directives. Add using System.Collections.Generic; if your project doesn't use implicit usings.
Frequently Asked Questions
With System.Text.Json, call JsonSerializer.Deserialize<Root>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }). Case-insensitive matching is needed because the generated property names are PascalCase while JSON keys are often camelCase. With Newtonsoft.Json, JsonConvert.DeserializeObject<Root>(json) works because it matches names case-insensitively by default.
The value was null in your sample, so its real type couldn't be determined. Replace object with the correct type, for example string? or int?.
No. It generates classes with { get; set; } auto-properties, which work with every .NET version. You can convert them to records or add ? annotations afterwards.
No. The conversion runs in your browser with JavaScript, and your JSON isn't sent to or stored on DevToolsWorld servers.
The converter shows the parser's error message instead of output. Use the JSON Formatter to validate and fix the document, then convert it again.
Yes. It's free and doesn't require an account or any installation.