JSON to C# Class
Paste JSON, get C# classes with the right serializer attributes.
One JSON document, or several samples one after another or one per line (JSON Lines). Comments and trailing commas are ignored. Your data stays in this browser.
Types and inference
About the JSON to C# Class
Paste a JSON response and get C# classes for it: PascalCase properties (productId → ProductId) mapped back to the exact JSON names with [JsonPropertyName] for System.Text.Json or [JsonProperty] for Newtonsoft.Json. Nested objects become their own classes, arrays List<T> or T[], integers long, decimals double or decimal, ISO dates DateTimeOffset and UUIDs Guid. Values that are null in some samples become nullable (string?, double?), and properties missing from some samples are skipped when they are null on output.
Choose classes with attributes, complete code with FromJson/ToJson helpers and converters, or plain classes without attributes; add required-property checks; and download one .cs file per class as a ZIP. It all runs in your browser, so the JSON never leaves your device.
How to use it
- Paste JSON or open or drop a .json file, or press Load sample. Several samples one after another (or JSON Lines) show which properties are optional.
- Set the Root class name and the Namespace, and choose System.Text.Json or Newtonsoft.Json.
- Pick the Output: classes with attributes, complete code with FromJson/ToJson, or classes only. Choose
List<T>or arrays and the C# version. - Tick Fail when required properties are missing to add
[JsonRequired]orRequired.Always. - Copy the code or download the
.csfile — or tick One file per class and download them all as a ZIP.
Examples
{"id": 1, "name": "Ada", "email": null, "tags": ["a"]}
{"id": 2, "name": "Bob", "email": "[email protected]", "tags": [], "nick": "bobby"}public partial class User
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("email")]
public string? Email { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("nick")]
public string? Nick { get; set; }
}Root class name User; shown without the namespace and using lines.
The same two samples, Newtonsoft.Json, “Fail when required properties are missing” ticked
[JsonProperty("id", Required = Required.Always)]
public long Id { get; set; }
[JsonProperty("email", Required = Required.AllowNull)]
public string? Email { get; set; }
[JsonProperty("nick", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public string? Nick { get; set; }Always: must be present and not null; AllowNull: must be present, may be null; DisallowNull: may be missing, but not null.
Common uses
- Creating DTOs for a REST API client in ASP.NET Core, MAUI, Unity or a console app.
- Deserializing webhook payloads and config files with System.Text.Json or Json.NET.
- Turning a JSON Schema into model classes for a .NET service.
- Replacing Visual Studio’s “Paste JSON as Classes” with output that has attributes, nullability and required checks.
The three kinds of output
- Classes with attributes (default): every property has
[JsonPropertyName("…")](System.Text.Json) or[JsonProperty("…")](Newtonsoft.Json), so the C# names can be PascalCase while the JSON keeps its own names. Properties that were missing from some samples get[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]orNullValueHandling.Ignore. - Complete: the same, plus
Product.FromJson(json), aToJson()extension method and aConverterwith the serializer settings — including converters for enums and dates. - Classes only: plain properties without attributes. System.Text.Json then matches names exactly (case-sensitive), so set
PropertyNameCaseInsensitive = truefor camelCase JSON, orPropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower(.NET 8 or later) for snake_case JSON.
Enums and the Converter class
When a string property has a fixed set of values (at least 10 values in your samples with few distinct ones, or an enum in a JSON Schema), it becomes a C# enum such as public enum Role { Admin, InProgress, Viewer };. JSON values like "in-progress" cannot be enum member names, so the code includes a converter that maps each value. In Classes with attributes output the converters are collected in Converter.Settings: pass them when you deserialize — JsonSerializer.Deserialize<Users>(json, MyApp.Models.Converter.Settings) — and the notes under the code say so. Complete output does this for you in FromJson.
Nullable reference types
With C# 8+ the code uses nullable reference types: string? for values that can be null and string for the rest. The file starts with #nullable enable, and warning CS8618 ("non-nullable property must contain a non-null value") is turned off around it, because the deserializer fills those properties in. Choose C# 6 or C# 5 for older projects; then reference types have no ?.
Limitations
- Types come from your samples: a property that only ever held a whole number is
longeven if the API can send2.5. Paste several real responses, or choosedecimal/doubleby editing. - The classes use
{ get; set; }properties; C# records,initsetters and therequiredkeyword are not generated. [JsonRequired]needs .NET 7 or later;JsonIgnoreCondition.WhenWritingNullneeds .NET 5 or later. With System.Text.Json, the converter code (for enums and dates, and in Complete output) usesDateOnlyandTimeOnly, so it needs .NET 6 or later whichever C# version you pick.- JSON Schema references must point inside the schema (
#/$defs/…); nothing is downloaded.
Privacy
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot. The code generator (about 330 KB compressed) is downloaded from this site once, like the rest of the page; your JSON is never uploaded.
Frequently asked questions
Is my JSON uploaded?
No. The classes are generated in your browser, in a background worker. The page works offline once it has loaded.
System.Text.Json or Newtonsoft.Json?
System.Text.Json is built into .NET Core 3.0 and later and is the default in ASP.NET Core. Choose Newtonsoft.Json (Json.NET) if your project already uses it — the attributes and the Converter differ, the classes are the same.
Why do I get a JsonException for an enum value?
System.Text.Json reads enums as numbers unless a converter is registered. Deserialize with the generated Converter.Settings (or use Complete output and call FromJson), which includes a converter that maps each JSON string to its enum member.
Can I get one file per class?
Yes. Tick One file per class: each class (including its partial FromJson part) gets its own .cs file with the namespace and using lines, and Download all (.zip) saves them together.
Why is a property nullable when it is never null in my JSON?
Either it is null in at least one sample, or — with All properties optional — every property is treated as optional. Value types that can be missing become long?, double? or bool? so that a missing value is not silently 0 or false.