About the JSON to C# Class tool
Deserialising JSON in .NET with System.Text.Json or Newtonsoft needs classes whose shape matches the payload. Visual Studio's Paste JSON as Classes helps, but it isn't always at hand and doesn't add serializer attributes or nullable annotations. This JSON to C# generator produces modern classes or records from a sample in seconds.
Each JSON object becomes a public class with auto-properties, or a positional record if you prefer immutable types. Property names are PascalCase, and with attributes on, each property gets [JsonPropertyName("original_key")] so System.Text.Json maps it exactly. Integers become long, decimals double, arrays List<T>, and keys that are null or missing from some items become nullable (string?, long?). Non-nullable strings and collections are initialised so the code compiles cleanly with nullable reference types enabled.
Nested objects become separate classes, and identical shapes are reused instead of being declared twice. You can wrap everything in a namespace. The generator runs locally in your browser.
How to use JSON to C# Class
- Paste JSON into “JSON sample”, open a file, or click “Load sample”.
- Set the “Root type name” and an optional “Namespace”.
- Choose “Declare as”: class with properties or positional record.
- Toggle “[JsonPropertyName] attributes”.
- Copy the result or download it as a .cs file.
Features
Classes or records
Mutable classes with get/set properties or concise C# 9 positional records.
System.Text.Json attributes
[JsonPropertyName] keeps the exact JSON key for every property.
Nullable-aware
Optional and null values produce nullable types, others are initialised to avoid warnings.
Collections as List<T>
Arrays of objects get their own element class with a singular name.
Optional namespace
Wraps all generated types in the namespace you enter.
When to use it
- Create models for an HttpClient call in an ASP.NET Core app.
- Deserialize a configuration JSON file into strongly typed options.
- Build DTOs for a Blazor or MAUI app from an API sample.
- Model webhook payloads in an Azure Function.
- Write unit tests that load JSON fixtures into typed objects.
Frequently asked questions
Does it work with Newtonsoft.Json?
The classes work with any serializer. The attributes are System.Text.Json's; for Newtonsoft, switch them off and use its default case-insensitive matching or add [JsonProperty] yourself.
Why long instead of int?
long is the safe choice when you only have a sample. Change it to int if you know values are small.
What does object? mean in the output?
The key was always null or held mixed types in the sample, so no specific type could be inferred.
Which .NET versions are supported?
Records and nullable annotations need C# 9 or later (.NET 5+). The class output also works on older versions if you remove the ? annotations.
Is my JSON uploaded?
No. The classes are generated in your browser.