DevToolsmith

JSON to C# Class Converter

Paste JSON to generate C# classes or records for System.Text.Json or Newtonsoft.Json. Properties are PascalCase with attributes that map to the original keys, nullable values use ?, and dates and GUIDs get proper types.

Runs 100% in your browser — nothing is uploaded

JSON
Tip: drop a file here361 chars · 361 bytes · 14 lines
C# classes
1,291 chars · 1,291 bytes · 57 lines

Tip: paste an array of several objects — keys missing from some of them become optional (nullable ?).

Example

JSON input
{
  "id": "b3c1a2e4-7f5d-4c3b-9a1e-2d4f6a8b0c1d",
  "title": "Quarterly report",
  "createdAt": "2026-03-14T09:26:53Z",
  "author": {
    "name": "Ada",
    "email": "ada@example.com"
  },
  "tags": [
    "finance",
    "q1"
  ],
  "reviewer": null
}
Generated C# (root name: Document)
using System.Text.Json;
using System.Text.Json.Serialization;

public class Document
{
    [JsonPropertyName("id")]
    public Guid Id { get; set; }

    [JsonPropertyName("title")]
    public string Title { get; set; } = "";

    [JsonPropertyName("createdAt")]
    public DateTimeOffset CreatedAt { get; set; }

    [JsonPropertyName("author")]
    public Author Author { get; set; } = new();

    [JsonPropertyName("tags")]
    public List<string> Tags { get; set; } = new();

    [JsonPropertyName("reviewer")]
    public JsonElement? Reviewer { get; set; }
}

public class Author
{
    [JsonPropertyName("name")]
    public string Name { get; set; } = "";

    [JsonPropertyName("email")]
    public string Email { get; set; } = "";
}
  • id looks like a UUID, so it became Guid; createdAt became DateTimeOffset.
  • reviewer was null in the sample, so its type is unknown: JsonElement?. Replace it with the real type.

Deserializing with System.Text.Json

using System.Text.Json;

var doc = JsonSerializer.Deserialize<Document>(json)!;
Console.WriteLine(doc.Author.Name);

// A JSON array
var docs = JsonSerializer.Deserialize<List<Document>>(json)!;

// Back to JSON, indented
var output = JsonSerializer.Serialize(doc, new JsonSerializerOptions { WriteIndented = true });

Type mapping

JSONC#
stringstring, or DateTimeOffset, DateOnly, Guid when detected
integerlong
decimal numberdouble
true / falsebool
objectclass or record
arrayList<T>
sometimes missing or nullT?
always null / mixed typesJsonElement (System.Text.Json) or object

Use decimal instead of double for money. DateOnly is supported by System.Text.Json from .NET 7; on older versions, use DateTime or turn off date detection.

Tips

  • In ASP.NET Core, [FromBody] Document doc uses these classes directly. The web defaults are already camelCase and case-insensitive.
  • For AOT and trimming, add a JsonSerializerContext with [JsonSerializable(typeof(Document))] to use source generation.
  • Need the same model elsewhere? Generate TypeScript for the frontend or Java for another service.

Frequently asked questions

How do I convert JSON to a C# class?

Paste a JSON sample into the tool above. It creates a class for every object with PascalCase properties, adds [JsonPropertyName] attributes that map to the original keys, and picks C# types such as string, long, double, bool, List<T>, DateTimeOffset and Guid. Paste the result into a .cs file.

System.Text.Json or Newtonsoft.Json?

System.Text.Json is built into .NET Core 3.0 and later, is faster and is the default in ASP.NET Core, so choose it for new code. Newtonsoft.Json (Json.NET) is still common in older projects and has more features for unusual JSON. The attribute differs: [JsonPropertyName] versus [JsonProperty].

Why add [JsonPropertyName] when the names only differ in case?

System.Text.Json matches property names case-sensitively by default, so a C# property Title will not pick up a JSON key title unless you set PropertyNameCaseInsensitive or use JsonSerializerDefaults.Web. The attributes make the mapping explicit and independent of serializer options.

Why do some properties end with = "" or = new()?

With nullable reference types enabled, a non-nullable string or object property must be initialized, or the compiler warns with CS8618. Initializing to an empty value keeps the type non-nullable. Values that can be null or missing in the JSON are declared nullable (string?, long?) instead.

Can I use records?

Yes. Choose Records to get positional records, which are immutable and support value equality. System.Text.Json has supported deserializing records since .NET 5, and the attributes use the property: target so they apply to the generated properties.