Overview
Generates C# classes or positional records from a JSON sample, with System.Text.Json or Newtonsoft.Json attributes, nullable reference types and nested classes for every object it finds. Paste an API response and get model types you can drop into an ASP.NET Core or .NET console project. The JSON is processed in your browser and never sent anywhere.
How It Works
Paste JSON or load the sample, then set the root class name and an optional namespace. Choose between classes with get and set properties or positional records, pick the serializer attribute style, and decide whether to emit #nullable enable and whether ISO 8601 strings should become DateTime. The C# output updates as you type, and you can copy it or download it as a .cs file named after the root class.
Step-by-Step Usage Guide
- Paste a representative JSON response, ideally one with every optional field present somewhere.
- Set the root class name and, if you use one, the namespace.
- Pick classes or records and the serializer your project uses.
- Turn DateTime detection and nullable reference types on or off to match your code style.
- Copy the code or download the .cs file and add it to your project.
Technical Specifications & Standards
The generator walks the whole document instead of the first item. When it meets an array of objects it merges every element into one type, so a field that appears in only some items, or is null in any of them, is marked nullable: value types get a question mark, such as int?, and reference types get one when nullable reference types are on. Numbers start as int, widen to long when a value is outside the Int32 range and to double as soon as any sample has a fraction. Keys are converted to PascalCase property names; a name that starts with a digit gets an underscore, and when the property name differs from the JSON key a [JsonPropertyName] or [JsonProperty] attribute keeps the mapping exact. Element classes are named from the singular of the array key, so orders produces Order, and colliding names become Item and Item2. A field that is always null, or an empty array, cannot be inferred and is typed as object or List<object> for you to refine.
Targeted Use Cases
- Creating DTOs for a third-party REST API in an ASP.NET Core service.
- Typing webhook payloads before deserializing them with System.Text.Json.
- Generating Unity or Xamarin model classes from a JSON config file.
- Migrating a Newtonsoft.Json codebase by regenerating models with JsonPropertyName attributes.
Notes & Gotchas
- Paste an array of several real items rather than one, so optional fields are detected as nullable.
- Replace object typed fields with a concrete type once you know what the API sends there.
- Keep DateTime detection off if the API mixes dates with other strings in the same field.
- Review numeric fields that might exceed int in production even if your sample is small.
Frequently Asked Questions
Does it support System.Text.Json and Newtonsoft.Json?
Yes. Choose System.Text.Json to get [JsonPropertyName] attributes and a using for System.Text.Json.Serialization, Newtonsoft.Json to get [JsonProperty] and using Newtonsoft.Json, or None to emit plain properties without attributes.
How does it decide which properties are nullable?
A property is nullable when its key is missing from at least one object in the merged samples or its value is null somewhere. Value types such as int and bool always get a question mark in that case; reference types get one when nullable reference types are enabled.
Can it generate C# records instead of classes?
Yes. The positional record option emits public record Name(...) with one parameter per field, and serializer attributes are applied with the property: target so they reach the generated properties.
What happens with JSON keys that are not valid C# names?
Keys are split on underscores, hyphens and case changes and rebuilt in PascalCase. A key that starts with a digit gets a leading underscore, and the attribute keeps the original key so serialization still round-trips.
Related tools
- JSON → Java Class Generator - Generate Java POJOs or Records from JSON samples with proper types, getters/setters, and Jackson/Gson annotations.
- JSON to TypeScript - Generate typed TypeScript interfaces from any JSON — nested objects, arrays, and unions handled automatically.
- JSON to Swift Codable Struct - Turn JSON into Swift Codable structs with CodingKeys for snake_case keys, optionals for missing or null fields and nested types, ready to decode with JSONDecoder.
- JSON → Kotlin Data Class - Generate Kotlin data classes from JSON with nullable types, default values, and kotlinx.serialization annotations.
- JSON ↔ TOML Converter - Bi-directional conversion between JSON and TOML formats with proper type mapping for dates, arrays, and nested tables.
- XML → JSON Converter - Parse XML documents into clean JSON trees with configurable attribute handling, text nodes, and array detection.