Csharp Class from JSON
Convert JSON to C# class - records or classes, JsonPropertyName (System.Text.Json or Newtonsoft.Json), init-only setters, required keyword, mixed-type detection. Free.
- Runs in your browser
- Nothing uploaded
- Free, no sign-up
Generate C# classes / records from JSON. Smart type inference (long vs int, ISO 8601 → DateTime, mixed-type arrays → List<object> with warning), JsonPropertyName attributes (System.Text.Json or Newtonsoft.Json), init-only setters, required keyword.
Generated C# code
How to Use Csharp Class from JSON
- Paste your JSON object. Live JSON validity check shows ✓ or specific parse error.
- Enter class name and (optional) namespace. Pick type kind (class or record), JSON attribute style, array style (List<T> or T[]).
- Toggle options: PascalCase properties, nullable reference types, init-only setters (C# 9+), required keyword (C# 11+).
- Click Generate (or Ctrl+Enter). The generated code appears below with syntax highlighting.
- Copy or download as
{ClassName}.cs. Drop into your .NET project - most options work in .NET 6 / 7 / 8.
Frequently Asked Questions
What’s the difference between class and record?
Class is mutable by default (with { get; set; }) and uses reference equality. Record (C# 9+) is for DTOs – value-equality is generated automatically, comparing by property values rather than reference. For JSON DTOs that you serialize/deserialize without modifying, records are usually the better choice. Records with init-only setters ({ get; init; }) are essentially immutable.
System.Text.Json vs Newtonsoft.Json – which?
System.Text.Json ships with .NET Core 3.0+ (no package install needed), is significantly faster, and is the modern recommendation. Newtonsoft.Json is the older standard, has more features (e.g., JsonExtensionData, custom contract resolvers), and is still widely used. The tool generates the correct attribute style for each: [JsonPropertyName] vs [JsonProperty]. They’re not interchangeable – pick to match your project’s reference.
What’s the “required” keyword for?
C# 11 added required to force properties to be initialized at construction. public required string Name { get; set; } means: if you write new Foo() without setting Name, the compiler errors. Useful for DTOs where every property is mandatory. Note: doesn’t conflict with nullable annotation – required string? means “must be set, but can be null”.
How are numbers typed?
int for integers up to 2^31-1 (2,147,483,647). long for integers between 2^31 and 2^53 (the limit of JavaScript’s Number precision). decimal for integers beyond 2^53 (rare). double for any non-integer (1.5, 99.99, etc.). For monetary values, you may want to manually change double to decimal in the output – JSON has no money type, so the tool can’t auto-detect.
How are dates typed?
Strings matching ISO 8601 format (2026-06-03T12:34:56Z, 2026-06-03) get typed as DateTime. For other date formats (Unix timestamps, RFC 2822) they stay as string – convert manually after deserialization. Note: DateTime doesn’t carry timezone information; for that, use DateTimeOffset (you’ll need to find/replace).
What about mixed-type arrays?
If your JSON has "data": [1, "hello", true], the elements have different types. The tool detects this and generates List<object> with a comment: // Note: source array had mixed element types. You’ll need to deserialize as JsonElement or dynamic and switch on the actual types at runtime.
What about reserved C# keywords as property names?
JSON keys like class, namespace, return are reserved in C#. The tool prefixes them with @: public string @class { get; set; }. This is valid C# syntax. Or, combine with JsonPropertyName attribute mode to keep the JSON key and rename the C# property: [JsonPropertyName("class")] public string ClassName { get; set; }.
What’s in the .cs file?
Plain C# source with using directives at top, optional namespace declaration, and one or more classes (one for the root + one per nested object). Indented per code-style conventions (4 spaces). Drop into Visual Studio, Rider, or VS Code with C# Dev Kit.
Is anything uploaded?
No. The parsing happens entirely in your browser – nothing is sent to a server, logged, or stored, and the tool keeps working offline once the page has loaded.
Related Tools
Go Struct from JSON →
Generate typed Go structs from a JSON sample, with exported field names and json…
Android AssetLinks JSON Generator - App Links →
Android AssetLinks JSON Generator files for Android App Links. Configure package names and SHA-256…
Convert BSON to JSON →
Convert MongoDB BSON hex dumps to readable JSON in your browser. Free, offline, client-side…
JSON Diff →
Compare two JSON values and see exactly what changed, listed by path.
JSON Escape and Unescape →
Escape text into a JSON string, or unescape a JSON string back into plain…
JSON Flattener →
Flatten nested JSON into a single level, using dot-notation keys for every nested value.
JSON Formatter and Validator →
Format, validate, and minify JSON with a 2-space, 4-space, or tab indent, right in…
JSON Path Finder →
List every value in a JSON document with its full path in dot and…
JSONPath Tester →
Test a JSONPath expression against your JSON and see every matching value.
JSON Key Sorter Online →
Sort the keys of a JSON object alphabetically, recursively through every nested object.
JSON to GraphQL Schema →
Generate a GraphQL schema from a JSON sample, with types inferred and nested objects…
JSON to Java POJO →
Generate Java POJO classes from a JSON sample, with field types inferred and nested…