JSON to C# Class — Generate C# Model Classes from JSON
Generate C# model classes from JSON. PascalCase properties, nullable types, JsonPropertyName attributes. Runs in your browser. No uploads, no limits.
JSON to C# Class
Convert JSON to C# model class with System.Text.Json attributes. Works entirely in your browser.
C# has been the language of enterprise software on the .NET runtime for twenty years, and JSON has been the lingua franca of web APIs for almost as long. The friction between the two has always been the impedance mismatch: C# is statically typed, JSON is dynamically typed, and the bridge between them is a deserializer that needs to know the shape of the data in advance. Hand-writing C# classes for every API response is repetitive, error-prone, and the first thing to drift out of sync when the API changes. Generating the classes from a sample JSON response is the standard fix, and the generated classes serve as the source of truth until the next API change forces a regeneration.
The non-obvious thing about C# class generation is naming convention. JSON keys are typically snake_case (user_id, created_at), and C# properties are PascalCase (UserId, CreatedAt). The generator handles the case conversion automatically and emits properties that match C# conventions, with optional [JsonPropertyName] attributes that preserve the original JSON key for deserialization. The default is to omit the attributes and rely on the deserializer’s case-insensitive matching — the right pick for new code that controls both ends. The attribute-emitting mode is the right pick for legacy codebases or APIs that use snake_case keys exclusively.
For a final hand-off: if the destination is an ASP.NET Web API controller, paste the generated classes into a Models folder and let the controller return them as JSON — the deserializer handles the round-trip. If the destination is a desktop or mobile app, add [JsonPropertyName] attributes to match the source API’s exact casing. If the destination is a Blazor or Razor Pages app, the generated classes work as the model for the page’s @model directive. The generated classes are a starting point — add validation attributes, XML doc comments, and business logic methods as the codebase matures.
How to use
Paste your JSON
Drop a JSON object or a JSON array of objects into the input. The generator walks the structure and emits a C# class for the root and a nested class for each object shape.
Pick output options
Choose between classes (mutable POCOs with public properties) and records (immutable C# 9+ records with init-only setters). Toggle nullable reference types to match a project that has `<Nullable>enable</Nullable>`.
Copy or download the classes
Copy the C# to your clipboard, or download as a .cs file. The output is paste-compatible with System.Text.Json and Newtonsoft.Json deserializers — no extra attributes required for basic usage.
Frequently asked
Does the output work with System.Text.Json?
Yes — by default the generator emits classes with PascalCase properties that match System.Text.Json's default deserialization. Toggle 'JsonPropertyName attributes' to emit `[JsonPropertyName("original_key")]` for projects that use snake_case JSON keys with PascalCase C# properties.
How are nested objects handled?
Nested objects become nested classes with PascalCase names derived from the JSON key. A `user.profile.name` path in the JSON becomes a `User` class with a `Profile` property of type `Profile`, and a `Profile` class with a `Name` string property. Deeply nested structures are handled the same way at any depth.
What about JSON arrays?
JSON arrays become C# `List<T>` properties where T is the inferred element type. Arrays of objects become `List<NestedClass>`, arrays of strings become `List<string>`, and arrays of mixed types become `List<object>`. The generator emits `using System.Collections.Generic;` at the top of the file.
Will it generate records or classes?
Default is classes with public properties and a parameterless constructor. Toggle 'records' to emit C# 9+ positional or init-only records, which are immutable and work with `with` expressions. Records require .NET 5+ or .NET Standard 2.1+.
How does it handle null values?
By default, all reference type properties are emitted as nullable (`string?`, `int?`) when the project has nullable reference types enabled. For projects without nullable reference types, all properties are non-nullable — assign defaults in the constructor or use default value handling in the deserializer.
Limitations
- Inferred types are not validatedThe generator infers types from the sample data. A field that appears as a string in the sample may actually be an enum, a date, or a constrained integer. The generated C# uses the inferred type — review the output and add enums, `DateTime` conversions, or range attributes by hand.
- No System.Text.Json source generator outputThe output is POCO classes that work with the reflection-based deserializer. The newer source generator (System.Text.Json's `JsonSerializerContext`) requires a different code shape and is not emitted. For source generator compatibility, post-process the output to add the context class.
- No XML documentationThe generated classes have no XML doc comments. Add `///` summaries by hand or post-process the output with a documentation generator to make the classes IntelliSense-friendly.
Platform notes
- macOS
- Visual Studio for Mac, Rider, and VS Code with the C# extension all handle the generated classes. The browser tool is the right pick for one-off generation where opening an IDE is not worth the setup time.
- Windows
- Visual Studio and Rider both handle the generated classes. The browser tool is the right pick for one-off generation of types from a sample API response, or for content pasted from a chat or email that needs to land as C# classes.
- Linux
- For command-line work, `quicktype --lang csharp` is the standard equivalent. The browser tool is the right pick for one-off generation where installing Node and quicktype is not worth the setup time.
- Web
- Runs entirely client-side. Works offline once the page has loaded. Useful for restricted environments where command-line tools or a .NET SDK is not available.