JSON to C#
C# classes with System.Text.Json or Newtonsoft attributes from JSON.
About this tool
Paste JSON and get C# classes instantly. Choose System.Text.Json or Newtonsoft.Json, add a namespace, and optionally use long for whole numbers or arrays instead of List<T>. Copy the code into your project.
How the C# is generated
Every JSON object becomes a class and every key a PascalCase property (user_name โ UserName) with a [JsonPropertyName] or [JsonProperty] attribute that keeps the original key, so serialization round-trips exactly. Strings become string, whole numbers int (or long), decimals double, booleans bool, arrays List<T> and nested objects their own classes, named after the key (orders โ Order). Array items are merged before types are chosen, so a key that only some items have, or that is sometimes null, is treated as optional or nullable rather than breaking decoding. Those become nullable types such as string? and int?, and non-nullable strings, lists and objects get initialisers so the code compiles cleanly with nullable reference types enabled. Honest limits: the classes describe your sample. An ID that fits in int today may need long, a field that's always null becomes object?, and dates stay as strings unless you change them to DateTime. JSON to Java, JSON to TypeScript and the JSON formatter are related, and What JSON is, and where it trips people up explains the format.
Frequently asked questions
How do I convert JSON to a C# class?
Paste the JSON here and copy the generated classes. Each object becomes a class with attributed properties.
System.Text.Json or Newtonsoft?
System.Text.Json is built into modern .NET. Choose Newtonsoft if your project already uses Json.NET.
Why are some properties nullable?
Keys that are sometimes null or missing from some array items become nullable so deserialization doesn't fail.
Is my JSON uploaded?
No. Everything runs in your browser and nothing is stored or sent.