FormatterHQ

JSON to C# Class Generator

Generate C# classes from JSON: auto-properties with .NET types, nested classes, nullable values, and optional System.Text.Json attributes and helpers.

Input JSON
Output CSHARP
Ready.

How to use the JSON to C#

  1. Paste your JSON sample (an object, or an array of objects) into the Input editor, or use Sample, Upload file or Load URL, or press Sample to try one.
  2. Set the Top-level class name, for example Task; it is converted to PascalCase. Nested types are named after their property keys.
  3. Leave Types only (no helpers) off to get [JsonPropertyName] attributes and FromJson/ToJson helpers for System.Text.Json; tick it for bare classes.
  4. Press Generate (it also re-runs automatically as you edit), then use Copy or Download.

JSON to C#: generate classes for System.Text.Json

Deserializing JSON in .NET starts with classes that mirror the payload. This JSON to C# generator writes them for you from a sample: one partial class per object shape, auto-properties in PascalCase, and .NET types chosen from the values it sees. In full mode the output targets System.Text.Json, the serializer built into .NET, with attributes and converters ready to use.

Example

{
  "id": 42,
  "title": "Write docs",
  "done": false,
  "priority": 2.5,
  "tags": ["docs"],
  "owner": { "name": "Ada", "email": null },
  "due": "2026-10-01T09:00:00Z",
  "subtasks": [
    { "title": "Outline", "estimate": 2 },
    { "title": "Draft" }
  ]
}

With Types only checked:

namespace QuickType
{
    public partial class Task
    {
        public long Id { get; set; }
        public string Title { get; set; }
        public bool Done { get; set; }
        public double Priority { get; set; }
        public string[] Tags { get; set; }
        public Owner Owner { get; set; }
        public DateTimeOffset Due { get; set; }
        public Subtask[] Subtasks { get; set; }
    }

    public partial class Subtask
    {
        public string Title { get; set; }
        public long? Estimate { get; set; }
    }
}

Estimate is long? because one subtask lacks it. Whole numbers use long to avoid overflow surprises, decimals use double, arrays become C# arrays, and the ISO date string becomes DateTimeOffset, which keeps the time zone offset. The null-only email is typed as object.

Why the attributes matter

JSON keys are usually camelCase or snake_case, while C# properties are PascalCase. System.Text.Json matches property names case-sensitively by default, so Title will not pick up "title" unless you configure it. With Types only off, every property gets an attribute such as [JsonPropertyName("title")], so mapping works regardless of serializer options, even for keys like user_name or 2fa. The full output also includes:

  • Task.FromJson(string) and a ToJson() extension method.
  • A Converter.Settings object with converters for ISO dates, plus DateOnly and TimeOnly support.
  • A #nullable enable context and pragmas that silence nullable warnings in the generated file.

If you use bare classes instead, set PropertyNameCaseInsensitive = true or a JsonNamingPolicy in JsonSerializerOptions; ASP.NET Core's default options already use camelCase with case-insensitive matching.

Type mapping

JSONC#
integerlong (long? if optional)
decimaldouble
ISO date-timeDateTimeOffset
arrayT[]
objectpartial class named after the key
null only / mixedobject

For money, change double to decimal; binary floating point cannot represent values like 0.1 exactly. Change arrays to List<T> if you add items after deserializing.

Nullable reference types

The full output enables nullable reference types with #nullable enable. Properties that were always present in your sample are declared as non-nullable string, so the compiler assumes they are never null. If the real API can omit them, change them to string?; otherwise you may meet a NullReferenceException at runtime even though the compiler raised no warning.

Customizing the output

  • Namespace: replace QuickType with your project's namespace.
  • Records: for immutable DTOs, turn classes into public record Subtask(string Title, long? Estimate);; System.Text.Json supports records.
  • Newtonsoft.Json: if your project uses it, swap [JsonPropertyName] for [JsonProperty].
  • Required members: on C# 11+, mark mandatory properties with required to catch missing data at compile time when constructing objects.

Format the generated file with the C# Formatter. Working from XML? See XML to C#. To check your input, use the JSON Validator. All generation runs in your browser.

Frequently asked questions

Does the generated C# code use Newtonsoft.Json or System.Text.Json?
System.Text.Json. The full output uses [JsonPropertyName] attributes and JsonSerializerOptions. For Newtonsoft, switch the attributes to [JsonProperty].
Why doesn’t my types-only class deserialize any values?
System.Text.Json matches names case-sensitively by default, so PascalCase properties miss camelCase keys. Enable PropertyNameCaseInsensitive, use a naming policy, or keep the generated attributes.
Why is a number typed as long instead of int?
The generator uses long for integers so large IDs do not overflow. Change it to int if you know the values are small.
Can I generate records instead of classes?
The tool generates classes. Converting a simple class into a positional record is quick and works with System.Text.Json.
How are dates handled?
ISO 8601 date-time strings become DateTimeOffset. The full output includes converters for consistent parsing and formatting.

Last updated October 3, 2026

Related tools

XML to C# Generate C# classes with JsonProperty attributes from a XML sample instantly, with nested types detected automatically. JSON to Dart Generate Dart classes with fromJson and toJson from a JSON sample instantly, with nested types detected automatically. JSON to Elm Generate Elm type aliases with decoders from a JSON sample instantly, with nested types detected automatically. JSON to Flow Generate Flow Flow type definitions from a JSON sample instantly, with nested types detected automatically. JSON to Go Generate Go structs with json tags from a JSON sample instantly, with nested types detected automatically. JSON to Haskell Generate Haskell records with Aeson instances from a JSON sample instantly, with nested types detected automatically. JSON to Java Generate Java POJO classes with getters and setters from a JSON sample instantly, with nested types detected automatically. JSON to JavaScript PropTypes Generate JavaScript PropTypes React PropTypes definitions from a JSON sample instantly, with nested types detected automatically. JSON to JSON Schema Generate JSON Schema a JSON Schema document from a JSON sample instantly, with nested types detected automatically. JSON to Kotlin Generate Kotlin data classes from a JSON sample instantly, with nested types detected automatically. JSON to Laravel Model & Migration Generate a Laravel Eloquent model ($fillable, casts, relations) and a matching migration from a sample JSON record. JSON to Mongoose Schema Generate a Mongoose schema and model from a sample JSON document, detecting Date, ObjectId, arrays and nested objects.