JSON to C# Class Generator
Generate typed C# classes with System.Text.Json JsonPropertyName attributes from JSON.
- 100% free
- Private in browser
- No signup
- No watermarks
C# Classes (1)
using System.Text.Json.Serialization;
using System.Collections.Generic;
public class OrderDto
{
[JsonPropertyName("order_id")]
public long OrderId { get; set; }
[JsonPropertyName("customer")]
public string Customer { get; set; }
[JsonPropertyName("total")]
public double Total { get; set; }
}About JSON to C# Class Generator
The JSON to C# Class Converter generates C# model classes from a sample JSON payload. Paste an API response, set a root class name, and the tool writes public PascalCase properties, each with a [JsonPropertyName] attribute holding the original key, ready for System.Text.Json. Whole numbers become long, decimals become double, arrays become List<T>, and every nested object gets its own class. Types are inferred from the one sample you paste, so review fields that can be null or hold mixed values.
How to use JSON to C# Class Generator
- Enter a root class name, such as OrderDto.
- Paste your sample JSON into the Input JSON box.
- Review the generated classes and the class count in the C# Classes panel.
- Click Copy C# Code and paste the classes into your project.
Key features
- Public PascalCase properties with { get; set; } accessors
- [JsonPropertyName] on every property keeps the original JSON key
- Maps whole numbers to long, decimals to double, and booleans to bool
- Creates a separate class for each nested object, named after its key
- Types arrays as List<T> based on their first element
- Adds using lines for System.Text.Json.Serialization and System.Collections.Generic
Frequently asked questions
- How do I convert JSON to a C# class?
- Paste your JSON into the Input JSON box, set a root class name, and the classes are generated instantly. Click Copy C# Code to copy them into your project.
- Does the output work with Newtonsoft.Json?
- Not as generated. The classes use [JsonPropertyName] from System.Text.Json. For Newtonsoft.Json, replace each attribute with [JsonProperty("key")] and change the using line to Newtonsoft.Json.
- Which C# types are used for JSON numbers?
- Whole numbers become long and numbers with a decimal part become double. Change them by hand where another type fits better, such as int for small counters or decimal for money.
- How are null values and empty arrays typed?
- A null value becomes object? and an empty array becomes List<object>, because the sample gives no type to infer. Replace them with the real type, such as string? or List<OrderLine>, once you know the shape.
- Why do I get nullable warnings on the generated properties?
- The generator writes non-nullable reference types such as string without initializers, so a project with nullable reference types enabled reports warning CS8618. Mark fields that can be missing as string?, or add the required modifier.
Related In-Depth Guides
Learn practical workflows, real-world examples, and expert tips in our comprehensive guides:
Password Entropy Explained: How Bits Measure Brute-Force Cracking Time
Understand Shannon entropy in passwords, character pool combinations, and how many seconds, years, or millennia it takes GPUs to crack modern passphrases.
How to Convert Docker Run Commands to Docker Compose YAML Files
A comprehensive developer guide to transforming complex docker run commands into clean, maintainable docker-compose.yml files.
Web Accessibility & Color Contrast (WCAG 2.1): How to Design AA & AAA Palettes
A practical guide to color contrast ratios, accessibility compliance, WCAG 2.1 AA/AAA standards, and building accessible UI palettes.
Rate this tool
Be the first to rate — helps others and improves this page.