JSON to C#

Generate C# Classes
from JSON

Paste any JSON and instantly get typed C# class definitions with public properties. Perfect for .NET APIs, ASP.NET models, and JSON deserialization.

Open JSON to C# Converter

C# class definitions in four steps

Paste your JSON Drop any valid JSON object or array into the input — as compact or pretty-printed as you like.
Select C# output Switch to the Convert tab and choose C#. Class definitions are generated immediately.
Copy the class definitions One-click copy puts the generated C# code on your clipboard, ready to paste into your project.
Add to your .NET project Paste the classes into your codebase and use System.Text.Json or Newtonsoft to deserialize.

No account. No upload. No nonsense.

🔒

No Server

Your JSON never leaves your device. There is no backend to send it to.

.NET Ready

Generated classes target C# 9.0+ with auto-properties, compatible with .NET 6, 7, and 8.

📡

Works Offline

Load once and use forever — even on a plane or without internet access.

Related JSON tools

JSON to TypeScript Generate typed TypeScript interfaces from your JSON structure instantly.
JSON Formatter Pretty-print JSON with syntax highlighting and a collapsible tree view.
JSON Schema Validator Validate JSON against a Draft-07 schema with detailed error messages.
JSON Validator Check your JSON for syntax errors with clear, line-level error reporting.

Common questions answered

Is JSON to C# conversion free?

Yes, completely free with no signup required.

What C# version is the output targeting?

The output targets C# 9.0+ with auto-properties (get; set;). It works with all modern .NET versions including .NET 6, 7, and 8.

Does my data leave my browser?

No. All conversion is 100% client-side.

Are JSON property names preserved?

Yes. A [JsonPropertyName] attribute is added for properties where the JSON key differs from the C# property name convention.

How are nested objects handled?

Each nested JSON object becomes a separate C# class. Arrays become List<T> where T is the inferred element type.

Converting JSON to C# classes

C# uses classes or records for JSON data. System.Text.Json (modern) or Newtonsoft.Json deserialize JSON into these types. This tool generates complete C# class definitions with PascalCase properties, .NET types (string, int, double, bool), and [JsonPropertyName] attributes for proper mapping.

The converter follows .NET conventions: PascalCase class and property names, { get; set; } auto-properties, separate classes for nested objects, and List<T> for arrays. When JSON keys are camelCase, it adds [JsonPropertyName] attributes. The output targets C# 10+ with nullable reference types.

Convert JSON to C# classes
Input
{
  "userName": "Alice",
  "age": 30,
  "roles": ["admin"],
  "address": {
    "city": "Portland"
  }
}
Output
public class Root
{
    [JsonPropertyName("userName")]
    public string UserName { get; set; }
    [JsonPropertyName("age")]
    public int Age { get; set; }
    [JsonPropertyName("roles")]
    public List<string> Roles { get; set; }
    [JsonPropertyName("address")]
    public Address Address { get; set; }
}

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

Get the most out of this tool

Ready to generate your C# classes?

Free forever. No signup. Instant results.

Open JSON to C# Converter

C# classes for JSON with System.Text.Json and Newtonsoft

C# and the .NET ecosystem have two major JSON libraries: System.Text.Json (built into .NET Core 3.0+ and .NET 5+) and Newtonsoft.Json (Json.NET, the long-standing community standard). Both serialize and deserialize JSON to C# classes, but with different attribute names and behavior. The converter generates C# POCO (Plain Old CLR Object) classes with appropriate annotations for both libraries, giving you a head start on JSON integration in any .NET project.

JSON types map to C# types as follows: JSON strings become string (nullable reference type in C# 8+ with nullable context enabled). JSON integers become int or long. JSON floating-point numbers become double. JSON booleans become bool. JSON null maps to nullable types — string? or int? in C# 8+ with nullable reference types enabled, or just string for older code. JSON arrays become List<T> or T[]. Nested JSON objects become separate C# class definitions.

Property naming conventions differ between JSON (camelCase or snake_case) and C# (PascalCase). The converter generates PascalCase property names (as per C# conventions) and adds [JsonPropertyName("jsonKey")] (System.Text.Json) or [JsonProperty("jsonKey")] (Newtonsoft.Json) attributes to handle the name mapping. Alternatively, you can configure the serializer globally with JsonSerializerOptions using camelCase naming policy, eliminating the need for per-property attributes.

ASP.NET Core Web API uses System.Text.Json by default in .NET 6+. Controller actions returning objects are automatically serialized to JSON responses. [FromBody] parameters are automatically deserialized from the request body. The generated C# classes work directly as controller action parameter types and return types — no additional configuration is needed for basic JSON API development in ASP.NET Core.

Nullable reference types, introduced in C# 8 and enabled by default in .NET 6+ projects, add compile-time null safety similar to TypeScript. String becomes non-nullable by default — to allow null, you must write string?. When a JSON field might be absent or null, the converter marks its C# type as nullable. If your project has nullable reference types enabled, these annotations prevent null reference exceptions that would otherwise only surface at runtime.

Records, introduced in C# 9, provide an immutable alternative to regular classes for data transfer objects. A C# record with init-only properties is ideal for JSON deserialization when immutability is desired. The converter can generate records instead of classes — syntax is similar, but record types automatically implement value equality (two records with the same properties are equal) and provide with-expressions for non-destructive mutation.

When developers use this tool

ASP.NET Core API models Generate request and response model classes for ASP.NET Core Web API controllers. The generated classes work directly with model binding, validation attributes, and System.Text.Json serialization.
HttpClient JSON integration When calling external REST APIs with HttpClient, generate the response model class from the API documentation. Use ReadFromJsonAsync<T>() for clean, typed response deserialization.
Azure Function development Azure Functions often receive JSON payloads from HTTP triggers, Service Bus, or Event Grid. Generate C# classes to deserialize these payloads with strong typing rather than working with dynamic or JObject.
Blazor app data binding Blazor WebAssembly apps that fetch JSON from APIs need C# models for data binding with @bind directives and component parameters. Generate the model from the API JSON to wire up data flow immediately.

Additional frequently asked questions

Should I use System.Text.Json or Newtonsoft.Json for new projects?

For new .NET 6+ projects, System.Text.Json is the recommended choice — it is faster, built-in, and well-integrated with ASP.NET Core. Use Newtonsoft.Json when you need features it uniquely offers: polymorphic deserialization, JSON Path queries, or compatibility with legacy codebases that already use it extensively.

How do I handle JSON properties that are C# reserved keywords?

Use the @-prefix verbatim identifier: @event, @class, @namespace. Alternatively, rename the property and use [JsonPropertyName("event")] to map it to the JSON key. The @-prefix approach keeps the attribute count down; the rename approach produces more readable property names.

Can I use the generated C# classes with Entity Framework Core?

C# classes generated for JSON are compatible with EF Core when decorated with appropriate data annotations like [Key], [Required], and [Column]. For storing JSON columns in databases, EF Core supports JSON columns in PostgreSQL (using Npgsql), SQL Server (using EF Core 7's JSON columns feature), and SQLite.

What is the difference between class and record for JSON DTOs in C#?

Classes are mutable by default and use reference equality. Records are immutable by default (with init-only properties) and use value equality. For JSON data transfer objects that you only read (deserialization), records are more semantically correct and provide equality comparison that works in unit tests. For objects you need to mutate after creation, use regular classes.