Convert JSON to C# class!

Input JSON to generate C# class code, including nested objects! Supports System.Text.Json [JsonPropertyName] for .NET and ASP.NET Core.
JSON
Result
 

Convert JSON to C# class!

Convert JSON into C# classes for System.Text.Json. Property names are turned into PascalCase, and every property carries a [JsonPropertyName] attribute so it binds to the exact original key.

It saves the copy-and-type work for ASP.NET Core request and response models, types for HttpClient.GetFromJsonAsync<T>() calls to external APIs, and data classes in Unity or MAUI apps.

How to use

  1. Paste a JSON response or configuration file.
  2. Enter the root class name in Type name (for example PaymentResult).
  3. Drop the generated classes into a .cs file and add your namespace.
  4. Use it with JsonSerializer.Deserialize<PaymentResult>(json) or GetFromJsonAsync<PaymentResult>(url).

Example

Input (JSON)
{
  "paymentId": "pay_8f2k",
  "amount": 15000,
  "currency": "KRW",
  "approved": true,
  "approvedAt": "2024-05-01T12:30:00Z",
  "card": { "issuer": "VISA", "last4": "4242" },
  "metadata": null
}
Output (C# · System.Text.Json)
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

public class PaymentResult
{
    [JsonPropertyName("paymentId")]
    public string PaymentId { get; set; } = string.Empty;

    [JsonPropertyName("amount")]
    public int Amount { get; set; }

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

    [JsonPropertyName("approved")]
    public bool Approved { get; set; }

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

    [JsonPropertyName("card")]
    public Card Card { get; set; } = new();

    [JsonPropertyName("metadata")]
    public JsonElement? Metadata { get; set; }
}

public class Card
{
    [JsonPropertyName("issuer")]
    public string Issuer { get; set; } = string.Empty;

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

Every property has [JsonPropertyName], so paymentId ↔ PaymentId matches regardless of casing rules. metadata is only ever null, so its type is unknown and it becomes JsonElement?. String and object properties get string.Empty / new() initializers so the code compiles without nullable warnings.

Supported features

  • [JsonPropertyName("originalKey")] on each property, with using System.Text.Json.Serialization;.
  • Types: string, int, long for integers beyond 32 bits, double for decimals, bool, and List<T> for arrays.
  • Values of mixed or unknown type become JsonElement, adding using System.Text.Json;.
  • Properties missing from some items or containing null become nullable (int?, string?).
  • Required properties get = string.Empty; or = new(); initializers to avoid nullable reference warning CS8618.
  • A property that would share its class's name is not allowed in C#, so it gets a Value suffix (e.g. RootValue).
  • A top-level array yields a // Root: List<RootItem> comment and the element class.

Use cases

Calling external APIs with HttpClient

Convert a sample response from a payment or shipment-tracking API and use it as the type in await http.GetFromJsonAsync<PaymentResult>(url), instead of pulling fields one by one out of a JsonDocument.

Webhook payload models in ASP.NET Core

Generate classes from the payload a third-party service posts to you and accept them as a [FromBody] parameter, so model binding and validation work as usual.

appsettings and game data files

Pinning the structure of a JSON data file read by a Unity or console app to classes means a changed data file surfaces as a deserialization error right away.

Notes and limitations

  • Newtonsoft.Json ([JsonProperty]) output is not generated. If you use Json.NET, switch the attributes to [JsonProperty("key")].
  • Date strings stay string. For ISO 8601 values, changing the type to DateTime or DateTimeOffset is enough for System.Text.Json to parse them.
  • Target-typed new() and string? assume C# 9+ with the nullable context enabled (the default since .NET 6).
  • No record or required output. For immutable models, change { get; set; } to { get; init; }.
  • All classes come in one block; split files and namespaces yourself.

FAQ

Why add [JsonPropertyName] even when the key already matches?

System.Text.Json is case-sensitive by default. In console or worker projects without custom JsonSerializerOptions, paymentId would not bind to PaymentId, so the attribute is always written to work regardless of configuration.

How do I read a JsonElement? property?

Check ValueKind, then use GetString(), GetInt32() or Deserialize<T>(). Once you know the real type, replacing JsonElement with it is the cleaner option.

Can I keep camelCase property names?

The output follows the C# PascalCase convention. The original key lives in [JsonPropertyName], so you can rename properties freely as long as the attribute stays.

Does it work with Unity's JsonUtility?

JsonUtility only handles public fields of [Serializable] classes, not properties, and ignores [JsonPropertyName]. In Unity, pair the output with the Newtonsoft.Json package or System.Text.Json instead.