JSON to C# Converter
Generate C# models from a JSON payload with the serialisation attributes and nullability your project expects.
Your data stays on your device
Input — JSON
- characters
- 0
- lines
- 0
- size
- 0 B
Output — C#
- characters
- 0
- lines
- 0
- size
- 0 B
Options
About this tool
C# conventions differ from JSON conventions: properties are PascalCase while JSON keys are usually camelCase or snake_case. Bridging that gap requires an attribute on every property, which is exactly the kind of code worth generating.
You can emit classic classes with auto-properties or positional records, target either System.Text.Json or Newtonsoft.Json, and enable nullable reference types so the compiler knows which fields may be absent.
How to use this tool
- Paste your JSON sample.
- Choose class or record output.
- Select the serialiser attribute style and whether to enable nullable reference types.
- Press Generate and copy the code into your project.
Key features
- class with auto-properties, or positional record
- System.Text.Json [JsonPropertyName] or Newtonsoft [JsonProperty] attributes
- Nullable reference types with ? annotations where values may be null
- List<T> for arrays with unified element types
- PascalCase property names with the original key kept in the attribute
- C# keywords escaped with @ so the output always compiles
Example
Input — JSON
{"order_id":"A1","total":42.5}Output — C#
public class Root
{
[JsonPropertyName("order_id")]
public string? OrderId { get; set; }
[JsonPropertyName("total")]
public double Total { get; set; }
}Good to know
- No namespace or using directives are emitted; those depend on your project layout.
- Records are immutable by default, so choose class output when you need settable properties.
- Numeric types are inferred as int, long or double from the sample; a value near a boundary may need manual widening.
Frequently asked questions
System.Text.Json or Newtonsoft?
System.Text.Json ships with .NET and is faster. Newtonsoft.Json remains more flexible for unusual converters and is still common in older codebases.
Why enable nullable reference types?
Because JSON fields are frequently absent. With nullable annotations the compiler warns you at the point where you dereference a value that might not be there.
Class or record?
Records suit immutable DTOs and give you value equality for free. Classes are the right choice for models that get mutated or that a framework must construct without arguments.
What about a key named "class" or "event"?
The property is emitted with an @ prefix, which makes a reserved word a legal identifier in C#, and the original key stays in the attribute.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.