JSON to C# Class Generator

Generate typed C# classes with System.Text.Json JsonPropertyName attributes from JSON.

  • 100% free
  • Private in browser
  • No signup
  • No watermarks

C# Classes (1)

using System.Text.Json.Serialization;
using System.Collections.Generic;

public class OrderDto
{
    [JsonPropertyName("order_id")]
    public long OrderId { get; set; }

    [JsonPropertyName("customer")]
    public string Customer { get; set; }

    [JsonPropertyName("total")]
    public double Total { get; set; }

}

About JSON to C# Class Generator

The JSON to C# Class Converter generates C# model classes from a sample JSON payload. Paste an API response, set a root class name, and the tool writes public PascalCase properties, each with a [JsonPropertyName] attribute holding the original key, ready for System.Text.Json. Whole numbers become long, decimals become double, arrays become List<T>, and every nested object gets its own class. Types are inferred from the one sample you paste, so review fields that can be null or hold mixed values.

How to use JSON to C# Class Generator

  1. Enter a root class name, such as OrderDto.
  2. Paste your sample JSON into the Input JSON box.
  3. Review the generated classes and the class count in the C# Classes panel.
  4. Click Copy C# Code and paste the classes into your project.

Key features

  • Public PascalCase properties with { get; set; } accessors
  • [JsonPropertyName] on every property keeps the original JSON key
  • Maps whole numbers to long, decimals to double, and booleans to bool
  • Creates a separate class for each nested object, named after its key
  • Types arrays as List<T> based on their first element
  • Adds using lines for System.Text.Json.Serialization and System.Collections.Generic

Frequently asked questions

How do I convert JSON to a C# class?
Paste your JSON into the Input JSON box, set a root class name, and the classes are generated instantly. Click Copy C# Code to copy them into your project.
Does the output work with Newtonsoft.Json?
Not as generated. The classes use [JsonPropertyName] from System.Text.Json. For Newtonsoft.Json, replace each attribute with [JsonProperty("key")] and change the using line to Newtonsoft.Json.
Which C# types are used for JSON numbers?
Whole numbers become long and numbers with a decimal part become double. Change them by hand where another type fits better, such as int for small counters or decimal for money.
How are null values and empty arrays typed?
A null value becomes object? and an empty array becomes List<object>, because the sample gives no type to infer. Replace them with the real type, such as string? or List<OrderLine>, once you know the shape.
Why do I get nullable warnings on the generated properties?
The generator writes non-nullable reference types such as string without initializers, so a project with nullable reference types enabled reports warning CS8618. Mark fields that can be missing as string?, or add the required modifier.

Rate this tool

Be the first to rate — helps others and improves this page.