JSON to C# Class Generator

Create C# classes or records with System.Text.Json attributes from example JSON.

100% Client-Side Processing — your data never leaves this browser. Works offline. How it works

0 lines • 0 bytes Ready
Tip: drop a file anywhere on the editor
Input
Paste, type or drop a file
1
Result
Updates as you type
// Output will appear here…
About this tool

How the JSON to C# Class works

Generate C# classes or records from JSON with [JsonPropertyName] attributes, nullable reference types and List<T>. Ready for System.Text.Json.

How to use the JSON to C# Class

  1. Paste JSON.
  2. Choose class or record and set the root type name.
  3. Copy the code into your project.

JSON to C# Class example

Input
{"id":7,"user_name":"aarav","rating":4.5}
Result
using System.Text.Json.Serialization;

public class User
{
    [JsonPropertyName("id")]
    public int Id { get; set; }

    [JsonPropertyName("user_name")]
    public string UserName { get; set; } = string.Empty;

    [JsonPropertyName("rating")]
    public double Rating { get; set; }
}

When to use it

  • Deserializing API responses in ASP.NET Core or Blazor.
  • Defining DTOs for minimal APIs.
  • Reading JSON settings in console apps.

Tip: Paste several array items so properties that are sometimes missing are detected as nullable.

Class or record

Classes with { get; set; } properties, or positional records with property attributes.

Exact key mapping

[JsonPropertyName] keeps the original JSON key while properties use PascalCase.

Nullable aware

Optional and null fields become string?, int? and so on; required strings default to string.Empty.

Rich types

long for large numbers, double, bool, DateTimeOffset for ISO timestamps and List<T> for arrays.

FAQ

Common questions

Which serializer is targeted?

System.Text.Json (.NET Core 3.0 and later). For Newtonsoft.Json, replace [JsonPropertyName] with [JsonProperty].

Why do some properties end with ?

They were null or missing in your sample, so they are nullable.

Does it need nullable reference types?

The output assumes <Nullable>enable</Nullable>, which is the default for new .NET projects.

Is my JSON private?

Yes, generation happens in your browser.