WebToolsPlanet
Converter Tools

JSON to C# Converter

Paste a JSON object and get ready-to-use C# classes — with field types, nested classes, and optional `[JsonPropertyName]` attributes for `System.Text.Json`.

Last updated: May 27, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is JSON to C# Converter?

When consuming a JSON API from .NET, you typically declare C# classes that mirror the JSON shape, then use `JsonSerializer` (`System.Text.Json`) or `JsonConvert` (Newtonsoft) to deserialize. Writing those classes by hand is tedious — each field needs a type and a property declaration, and JSON keys that don't match C# naming conventions need a `[JsonPropertyName("...")]` attribute to map correctly.

This tool reads a JSON example and emits the matching class hierarchy. Integers within `int` range use `int`, larger integers use `long`, decimals use `double`, strings use `string`, booleans use `bool`, and nested objects produce nested classes. Arrays become `List<T>` where T is the inferred element type. PascalCase field names follow C# conventions, with a JSON-name attribute added when the JSON key differs.

How to Use JSON to C# Converter

1

Paste a JSON object (root must be an object).

2

Set the root class name and an optional namespace.

3

Toggle auto-properties, PascalCase, [JsonPropertyName], and nullable types.

4

Copy the generated classes into your project.

Common Use Cases

  • Bootstrapping C# DTOs from a sample API response.
  • Generating model classes for System.Text.Json or Newtonsoft.Json deserialization.
  • Producing record-like model classes for ASP.NET Core controllers.
  • Translating an OpenAPI example into C# classes.

Example Input and Output

A flat JSON object generates a C# class with auto-properties.

JSON input
{ "userId": 42, "name": "Alice", "active": true }
Generated C# class
public class Root
{
    [JsonPropertyName("userId")]
    public int UserId { get; set; }
    public string Name { get; set; }
    public bool Active { get; set; }
}

Privacy

All conversion happens in your browser. No JSON is sent to a server.

Reserved keywords

If a JSON key matches a C# keyword (class, namespace, etc.), the field is prefixed with @ to escape it.

Nullable reference types

Enable "Nullable types (T?)" when your project has #nullable enable. The generator adds ? to every reference type so the compiler knows JSON can be missing.

Frequently Asked Questions

Auto-properties or fields?
C# convention favors auto-properties (get; set;) over public fields. Both compile to the same wire format. Pick fields only if you need exact memory layout or are emitting source for a serializer that prefers them.
System.Text.Json vs Newtonsoft.Json?
The generated [JsonPropertyName] attribute is the System.Text.Json (.NET Core 3.0+) attribute. For Newtonsoft.Json (Json.NET), rename it to [JsonProperty] after generation — both libraries do the same thing.
How are integer types decided?
Integers within int32 range (±2,147,483,647) use int. Larger integers use long. Any number with a decimal uses double — switch to decimal manually for monetary values.
Does this support records?
Not directly — the output uses classes with auto-properties. Convert to a record manually for an immutable type with value-based equality.
Does this send my JSON anywhere?
No. All generation happens locally in your browser.