JSON to C# Class
Paste a JSON sample and get back C# POCO classes ready to paste into a .cs file. Picks sensible types, handles nested objects with additional class definitions, supports nullable reference types, and emits either System.Text.Json or Newtonsoft.Json attributes depending on your project.
How to convert JSON to C#
-
1
Paste the JSON
A single sample is enough. Multiple samples improve nullable and array-item inference.
-
2
Pick the style
System.Text.Json (.NET 6+) or Newtonsoft.Json (legacy). PascalCase property names with `[JsonPropertyName]` for camelCase JSON.
-
3
Pick target C# version
C# 10+ for records and file-scoped namespaces, C# 8 for nullable reference types, or older for maximum compatibility.
-
4
Copy the classes
One root class plus nested classes for each object shape, all in one file ready to drop into your project.
Example output
For input:
{ "firstName": "Alice", "age": 30, "emails": ["a@a.com"], "address": { "city": "Madrid" } }
System.Text.Json output (C# 10+):
public class User
{
[JsonPropertyName("firstName")]
public string FirstName { get; set; } = default!;
[JsonPropertyName("age")]
public int Age { get; set; }
[JsonPropertyName("emails")]
public List<string> Emails { get; set; } = new();
[JsonPropertyName("address")]
public Address Address { get; set; } = default!;
}
public class Address
{
[JsonPropertyName("city")]
public string City { get; set; } = default!;
}
Type mapping
| JSON | C# type |
|---|---|
| string | string |
| integer | int (or long for > int.MaxValue) |
| number (decimal) | double (or decimal if opted in) |
| boolean | bool |
| null | object? (or merged with sibling) |
| ISO-8601 date | DateTime (or DateOnly) |
| GUID-shaped string | Guid |
| array of strings | List<string> |
| object | Nested class |
Attribute options
- System.Text.Json (
[JsonPropertyName("foo")]), preferred for .NET 6+ and new projects. - Newtonsoft.Json (
[JsonProperty("foo")]), for legacy projects or when you need Newtonsoft-specific features. - None, property names match JSON keys exactly (works only if JSON keys are PascalCase already).
Common mistakes
- Using
intfor a field that might overflow. If your JSON has values that exceedint.MaxValue, uselong. The generator promotes automatically when it sees large values. - Missing
[JsonIgnore]for computed properties. If you add helper props to the generated class, decorate them with[JsonIgnore]or they will serialize on the way out. - Forgetting culture-invariant parsing.
decimalfields should deserialize withCultureInfo.InvariantCulture; System.Text.Json does this by default, Newtonsoft with global settings. - Trusting the generator with one sample. Nullability and array-item types are guessed from what it sees. Always sanity-check nullable annotations against your actual API behaviour.
Frequently Asked Questions
For new projects on .NET 6+, use System.Text.Json, it is faster, built-in, and now supports nearly every feature Newtonsoft does. Use Newtonsoft for legacy projects or when you need its specific features (custom contract resolvers, JObject, dynamic handling).
Records are idiomatic for immutable DTOs in C# 10+. They give you value equality and concise syntax. Classes are better when you need mutation or legacy compatibility. The tool lets you pick either.
If your project uses nullable reference types (C# 8+), fields observed as null in any sample become string?, int?, etc. Without NRT, nullability is signalled only for value types (e.g. int?).
Mixed arrays of different object shapes are not directly representable in strongly-typed C#. The tool infers a common base class or (fallback) object; for mixed arrays you usually want to redesign the JSON.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- JSON till C#-klass [SV]
- JSON na klasę C# [PL]
- JSON zu C# Klasse [DE]
- JSON a Clase C# [ES]
- JSON ke Kelas C# [ID]
- JSONからC#クラスへ [JA]
- JSON ถึงคลาสใน C# [TH]
- JSON para Classe C# [PT]
- تحويل JSON إلى فئة C# [AR]
- JSON vers classe C# [FR]
- Từ JSON đến lớp C# [VI]
- JSON을 C# 클래스로 [KO]
- JSON naar C#-klasse [NL]
- JSON in classe C# [IT]
- JSON в класс C# [RU]
- JSON'ten C# Sınıfına [TR]
- 从 JSON 到 C# 类 [ZH]