TXT · Text & Data tools

JSON to C# Class Converter

Top-level type
Serializer
C# version
Arrays
Numbers
Output
Namespace
JSON input
C# output
Inference
C#languageJSON sampleinput0types0lines out0chars out
Go to the full JSON to Types generator with all ten languages

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

C# classes from a JSON sample

Paste a response body and get public partial class declarations in a namespace, each property annotated with the JSON key it maps to. The classes are partial so you can add members in another file without touching the generated one.

Example

With Serializer on System.Text.Json and Output on Attributes only:

namespace QuickType
{
    public partial class Customer
    {
        [JsonPropertyName("id")]
        public long Id { get; set; }

        [JsonPropertyName("orders")]
        public Order[] Orders { get; set; }
    }

    public partial class Order
    {
        [JsonPropertyName("sku")]
        public string Sku { get; set; }

        [JsonPropertyName("gift")]
        public bool? Gift { get; set; }
    }
}

Gift is bool? because only some orders in the sample have it.

System.Text.Json or Newtonsoft

The two serializers differ in attribute names (JsonPropertyName against JsonProperty), in how enums and dates are converted, and in the helper code that Classes + converters emits. Pick the one your project already references; mixing them in one assembly is a common source of silent null properties.

Arrays switches collections between T[] and List<T>. Numbers switches fractional values between double and decimal; use decimal for money. Namespace sets the enclosing namespace, and Types only drops every attribute and helper for plain POCOs.

Limits

Union-typed fields have no direct C# equivalent, so the generator emits a small struct with one nullable member per type and a custom converter to fill it. Dates become DateTimeOffset when date inference is on. With C# 5 or 6 selected, nullable reference annotations are left out.

Frequently Asked Questions

System.Text.Json by default, with JsonPropertyName attributes and a JsonSerializerOptions setup. Switch Serializer to Newtonsoft.Json for JsonProperty attributes and JsonConvert helpers.

Classes + converters emits the namespace, the classes, and a static Converter with FromJson and ToJson methods. Attributes only keeps the classes and their property attributes and leaves the converter out.

A missing or null value in the sample makes the property nullable: bool? for a boolean, and object for a field that is always null. Numbers with no fraction are long; with a fraction, double, or decimal if Numbers is set to decimal.

Yes. The virtual properties checkbox marks every property virtual, which ORMs such as Entity Framework need for lazy loading proxies.

C# 8 by default, which allows nullable reference types. Pick 6 or 5 for older compilers; the generator avoids syntax the chosen version does not have.

Generate types for one language

Full JSON to Types Generator tool

Explore Our Tools

Browse all tools