JSON to C# Class Generator
Paste JSON and get C# classes for System.Text.Json: PascalCase properties with [JsonPropertyName] attributes, List<T> for arrays, nested classes, and nullable types where values can be missing.
JSON to C# Class
Runs in your browser — nothing you enter is uploaded or stored.
Scratchpad auto-saved
How it works — in four simple steps
No signup and nothing to install — it all runs in your browser.
Add your JSON
Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.
Set the options
Adjust the options above the boxes — the output updates instantly as you change them.
Check the result
Read the status line: it reports rows, keys and any value that couldn't be represented in C#.
Copy or download
Copy the C# or download it as a .cs file. Nothing was uploaded at any point.
Use decimal instead of double for money fields before shipping.
Features
Named types
Choose the root type name; nested objects become their own named types, and identical shapes are merged.
System.Text.Json attributes
[JsonPropertyName] on every property, nullable types for optional values and a file-scoped namespace.
Private by design
Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.
About the JSON to C# Class
In .NET, JSON is usually deserialised into plain classes (POCOs). This generator creates them from a sample: each object becomes a public class, each key a { get; set; } property named in PascalCase, and a [JsonPropertyName("original_key")] attribute keeps the mapping exact — so JsonSerializer.Deserialize<Root>(json) works without a naming policy.
Types are inferred across all elements: whole numbers become long, decimals double, booleans bool, strings string, arrays List<T>, nested objects their own class. Keys missing from some objects or null in some become nullable (long?, string?), which lines up with nullable reference types. Non-nullable strings, lists and nested objects are initialised (= string.Empty;, = new();) so the code compiles cleanly with <Nullable>enable</Nullable>.
The output uses a file-scoped namespace (C# 10 / .NET 6 and later). Identical shapes share one class.
Examples
A weather API response with snake_case keys, a nested location, a list of hourly readings and a nullable field.
{
"location": { "name": "Pune", "lat": 18.52, "lon": 73.86 },
"generated_at": "2026-10-21T06:00:00Z",
"hourly": [
{ "time": "2026-10-21T07:00:00Z", "temp_c": 22.4, "rain_mm": 0, "alert": null },
{ "time": "2026-10-21T08:00:00Z", "temp_c": 24.1, "rain_mm": 0.2, "alert": "Light rain" }
]
}using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Weather.Api;
public class Forecast
{
[JsonPropertyName("location")]
public Location Location { get; set; } = new();
[JsonPropertyName("generated_at")]
public string GeneratedAt { get; set; } = string.Empty;
[JsonPropertyName("hourly")]
public List<HourlyItem> Hourly { get; set; } = new();
}
public class Location
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("lat")]
public double Lat { get; set; }
[JsonPropertyName("lon")]
public double Lon { get; set; }
}
public class HourlyItem
{
[JsonPropertyName("time")]
public string Time { get; set; } = string.Empty;
[JsonPropertyName("temp_c")]
public double TempC { get; set; }
[JsonPropertyName("rain_mm")]
public double RainMm { get; set; }
[JsonPropertyName("alert")]
public string? Alert { get; set; }
}This output was produced by the converter on this page with root Forecast in namespace Weather.Api — load it with the “Weather API” preset above and change any option to see the effect.
How JSON maps to C#
| In JSON | Becomes in C# |
|---|---|
"user_id": 7 | [JsonPropertyName("user_id")] public long UserId { get; set; } |
9.5 | double |
["a"] | List<string> = new(); |
| Nested object | its own class, initialised with = new(); |
| Missing or null somewhere | nullable type, e.g. string? |
| Mixed types | object? |
Things that trip people up
- Newtonsoft.Json. If your project uses Json.NET, replace [JsonPropertyName] with [JsonProperty] and the using with Newtonsoft.Json.
- decimal for money. Prices are inferred as double; switch to decimal for currency to avoid binary rounding.
- DateTime. ISO timestamps are typed string. Change them to DateTime or DateTimeOffset — System.Text.Json parses ISO 8601.
- Records. Prefer immutable records? Convert each class to public record Root(...) by hand; the property names and attributes carry over.
JSON vs C# at a glance
| Property | JSON | C# |
|---|---|---|
| Specification | RFC 8259 (2017) · ECMA-404 | System.Text.Json (.NET 6+) |
| File extension | .json | .cs |
| Media type | application/json | text/plain |
| Data types | string, number, boolean, null, object, array | string, long, double, bool, List<T> |
| Comments | No | Yes |
| Nesting | Unlimited | Named classes |
- JSON: Numbers are parsed as IEEE-754 doubles in JavaScript, so integers above 9,007,199,254,740,991 (2⁵³ − 1) lose precision.