Ready
Ln 1, Col 1Blog

Tool Kumar tool

JSON to C# classes

Generate C# models for System.Text.Json. The default output gives each property a JsonPropertyName attribute and uses required for fields present in every sample record.

How to use this tool

  1. Paste a representative response, including records whose fields differ.
  2. Review the generated output and change the root name if needed.
  3. Copy or download the code, then check the types against your API contract.

Worked example

This output comes from the built-in converter. The two item prices infer a floating-point field; the null and string notes infer a nullable field.

Input

{
  "user-id": 42,
  "profile": {
    "city": "London",
    "created_at": "2026-10-14T09:00:00Z"
  },
  "items": [
    {
      "price": 12,
      "note": null
    },
    {
      "price": 12.5,
      "note": "gift"
    }
  ]
}

Output

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

public class Root
{
    [JsonPropertyName("user-id")]
    public required long UserId { get; set; }

    [JsonPropertyName("profile")]
    public required Profile Profile { get; set; }

    [JsonPropertyName("items")]
    public required List<Item> Items { get; set; }
}

public class Profile
{
    [JsonPropertyName("city")]
    public required string City { get; set; }

    [JsonPropertyName("created_at")]
    public required string CreatedAt { get; set; }
}

public class Item
{
    [JsonPropertyName("price")]
    public required double Price { get; set; }

    [JsonPropertyName("note")]
    public required string? Note { get; set; }
}

Deserialize with System.Text.Json

Copy the classes into your .NET project and enable nullable annotations. JsonPropertyName attributes map PascalCase properties to the exact input keys.

Use a .NET version whose System.Text.Json supports required members, such as .NET 7 or newer. Configure serializer options for your application.

using System.Text.Json;

Root? model = JsonSerializer.Deserialize<Root>(responseBody);

Options and edge cases

  • The default is System.Text.Json. Choose Newtonsoft under More options to get Newtonsoft.Json JsonProperty attributes and JToken for unknown values.
  • Generated required members need C# 11 or newer. Nullable reference syntax assumes nullable annotations are enabled.
  • Integers use long, integers beyond signed 64-bit use decimal, and fractions use double. decimal also has a finite range; choose a custom representation for larger values.
  • A nullable field can still be required when every record contains its key. Required presence and accepting null are separate rules. Dates remain string.

Private by default

Your document stays in this browser. Tool Kumar parses, converts and creates downloads on your device, with no account or upload step.

JSON to C# classes questions

Does it use System.Text.Json or Newtonsoft.Json?
System.Text.Json by default, with JsonPropertyName attributes. Choose Newtonsoft in the converter's More options menu to emit Newtonsoft.Json JsonProperty attributes instead.
Which C# version does the output require?
C# 11 or newer for required members. Enable nullable reference types to use string? and other reference annotations as intended.
Why can a required property also be nullable?
The key appears in every sample record, but its value can be null. For example, required string? Note models presence separately from the value type.
Does it generate lists and nested classes?
Yes. Arrays of objects become List<Item>, and each nested shape gets a generated class.

Related tools

JSON to Java, JSON to TypeScript, JSON Schema generator.