Generate C# classes or records from a JSON example — PascalCase properties with [JsonPropertyName] attributes for System.Text.Json, nullable types for partially-present fields.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
From payload to .NET model
Paste a JSON example and get C# models ready for System.Text.Json: PascalCase properties with [JsonPropertyName] attributes wherever the JSON key differs (snake_case, dashes), nested objects as named classes, arrays as List<T>, and nullable types (long?, string?) for fields the sample proves optional. Choose classic classes or C# 9+ records for immutable DTOs.
Worked example
using System.Text.Json.Serialization;
public class Root
{
public long Id { get; set; }
[JsonPropertyName("order_status")]
public string OrderStatus { get; set; }
public Customer Customer { get; set; }
public List<Line> Lines { get; set; }
}When to use it
- Typing responses from third-party APIs in ASP.NET services.
- Building DTO layers from real payloads instead of docs.
- Keeping C# models in sync with the JSON contract during integration work.
Limitations to know
- Targets System.Text.Json; for Newtonsoft.Json swap the attribute to [JsonProperty] — the shape is identical.
- Optionality comes from evidence in arrays; single-object samples emit non-nullable properties — adjust against the real contract.
- Whole numbers become long and decimals double, for the same safety reasons as the Java converter.
Common errors and fixes
- Two classes named User and User2 — two different shapes shared a key name; align the shapes or rename after pasting.
- Missing rare fields — the sample did not contain them; paste a more complete example and regenerate.
How to use the JSON to C# Class Converter
- Paste a JSON example into the input panel.
- Set the root class name and choose class or record.
- Click "Generate C#".
- Paste into your project — the [JsonPropertyName] attributes are System.Text.Json-ready.
Frequently asked questions
How are snake_case JSON keys handled?
Properties become PascalCase per C# convention, and every renamed property gets a [JsonPropertyName("original_name")] attribute so System.Text.Json still maps it. For Newtonsoft.Json, swap in [JsonProperty] — same pattern.
When do properties become nullable?
When the sample proves optionality: fields missing from some array elements become long?, string?, bool? and so on. A single object cannot reveal optionality, so its fields are non-nullable — adjust against your real contract.
Class or record?
Records (C# 9+) give value equality and with-expressions — a natural fit for immutable DTOs. Classes with { get; set; } remain the default for mutable models and older framework targets.
Which JSON library does the output target?
System.Text.Json — the built-in serializer in modern .NET. The generated shape (properties + attributes) also works with Newtonsoft.Json after swapping the attribute namespace.