Skip to content
XUtilHub

JSON to C# Classes & Records Generator

Convert JSON to C# classes or records with System.Text.Json or Newtonsoft attributes. Nullable reference types, long vs int and nested classes handled.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to C#

Generate C# classes or positional records from JSON, with [JsonPropertyName] or [JsonProperty] attributes so PascalCase properties map back to your JSON keys exactly.

Key features

  • Classes with auto-properties or positional records
  • System.Text.Json [JsonPropertyName] or Newtonsoft [JsonProperty]
  • int vs long chosen from your values
  • Nullable reference and value types (string?, int?)
  • Non-nullable properties initialized to avoid CS8618 warnings
  • Optional namespace wrapper

C# models from JSON

ASP.NET Core APIs, Blazor apps, Azure Functions, MAUI apps and Unity projects all need C# classes that match JSON payloads. Paste a sample to get DTO classes or records with the right serialization attributes, ready to deserialize.

Example

{ "user_id": 7, "name": "Ada", "score": 4.5, "tags": ["admin"], "manager": null }
public class Root
{
    [JsonPropertyName("user_id")]
    public int UserId { get; set; }

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

    [JsonPropertyName("score")]
    public double Score { get; set; }

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

    [JsonPropertyName("manager")]
    public object? Manager { get; set; }
}
var root = JsonSerializer.Deserialize<Root>(json);

Type mapping

JSONC#
"text"string
42int (or long beyond 2,147,483,647)
3.14double
truebool
[...]List<T>
{...}class / record
null or missingT?

Tips

  • Money values: change double to decimal for prices and currency.
  • Dates: JSON dates are strings; change the type to DateTime or DateTimeOffset and the serializer parses ISO 8601 automatically.
  • Enums: replace string with an enum and add JsonStringEnumConverter.

Building the other side in Java or TypeScript? See JSON to Java and JSON to TypeScript.

How to use the JSON to C#

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The C# appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

System.Text.Json or Newtonsoft.Json?

System.Text.Json is built into .NET Core 3.0+ and is the default in ASP.NET Core. Choose Newtonsoft.Json for older projects or if you rely on its extra features.

Why does every property have an attribute?

System.Text.Json matches property names case-sensitively by default, so the attribute guarantees that PascalCase properties map to your JSON keys (for example user_id → UserId).

Class or record?

Records give immutability, value equality and concise syntax, which is ideal for DTOs. Classes with { get; set; } are better when you need to mutate objects or bind them to forms.

How are nullable fields typed?

Values that are null or missing in your sample become nullable (string?, int?, Address?). This works with nullable reference types enabled (<Nullable>enable</Nullable>).

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools