JSON to C#
Generate strongly typed C# classes and records with JsonPropertyName attributes, PascalCase properties, and nullable types.
- Runs in your browser
- Free, no signup
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Profile
{
[JsonPropertyName("bio")]
public string Bio { get; set; }
[JsonPropertyName("reputation")]
public int Reputation { get; set; }
}
public class Root
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("is_admin")]
public bool IsAdmin { get; set; }
[JsonPropertyName("roles")]
public List<string> Roles { get; set; } = new();
[JsonPropertyName("profile")]
public Profile Profile { get; set; }
}
Your files are processed locally in your browser and are not uploaded to our server.
Designing C# models for external API payloads or configuration files by hand is time-consuming. This converter inspects your JSON data, infers exact types, and generates idiomatic C# classes or modern C# 9+ records in seconds.
Each property is generated with a [JsonPropertyName("...")] attribute from System.Text.Json.Serialization, allowing your C# codebase to use clean PascalCase naming while flawlessly mapping to original JSON keys (including snake_case or kebab-case). Nested objects are decomposed into discrete classes, arrays become List<T>, and nullable values receive C# nullable markers (?).
How to use this tool
- Paste your JSON payload into the input editor or click "Load Sample" to explore an example.
- Select your preferred class style: standard C# Class or modern C# Record.
- Optionally enter a Namespace (e.g. MyApp.Models) to wrap your generated types in a namespace block.
- Click "Copy Code" or "Download .cs" to export the compiled C# source code directly to your project.
Native System.Text.Json Attribute Mapping
Modern .NET applications use System.Text.Json for high-performance, memory-efficient serialization. The generator decorates every property with [JsonPropertyName("original_key")].
This decouples your C# member naming conventions from external API schemas, ensuring clean domain modeling without breaking deserialization.
Classes vs Immutable Records
Choose between standard mutable C# classes with auto-properties ({ get; set; }) or positional records with init-only properties for immutable domain-driven design.
Records provide value-based equality, non-destructive mutation via "with" expressions, and concise syntax for data transfer objects (DTOs).
Frequently asked questions
Does this tool support nullable reference types in C# 8+?
Yes. Properties containing null values in the JSON sample are typed with the C# nullable reference annotation (such as string? or int?).
Can I customize the generated namespace?
Yes. Enter your namespace name into the "Namespace (optional)" field in the toolbar, and all generated types will be wrapped in that namespace.
Is any of my JSON uploaded to a server?
No. The converter runs 100% client-side in your web browser with zero server communications.