About the JSON to C#
Generate C# classes or positional records from JSON, with [JsonPropertyName] or [JsonProperty] attributes so PascalCase properties map back to your JSON keys exactly.
Key features
- Classes with auto-properties or positional records
- System.Text.Json [JsonPropertyName] or Newtonsoft [JsonProperty]
- int vs long chosen from your values
- Nullable reference and value types (string?, int?)
- Non-nullable properties initialized to avoid CS8618 warnings
- Optional namespace wrapper
C# models from JSON
ASP.NET Core APIs, Blazor apps, Azure Functions, MAUI apps and Unity projects all need C# classes that match JSON payloads. Paste a sample to get DTO classes or records with the right serialization attributes, ready to deserialize.
Example
{ "user_id": 7, "name": "Ada", "score": 4.5, "tags": ["admin"], "manager": null }
public class Root
{
[JsonPropertyName("user_id")]
public int UserId { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("score")]
public double Score { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; } = new();
[JsonPropertyName("manager")]
public object? Manager { get; set; }
}
var root = JsonSerializer.Deserialize<Root>(json);
Type mapping
| JSON | C# |
|---|---|
"text" | string |
42 | int (or long beyond 2,147,483,647) |
3.14 | double |
true | bool |
[...] | List<T> |
{...} | class / record |
| null or missing | T? |
Tips
- Money values: change
doubletodecimalfor prices and currency. - Dates: JSON dates are strings; change the type to
DateTimeorDateTimeOffsetand the serializer parses ISO 8601 automatically. - Enums: replace
stringwith an enum and addJsonStringEnumConverter.
Related tools
Building the other side in Java or TypeScript? See JSON to Java and JSON to TypeScript.
How to use the JSON to C#
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The C# appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.