JSON to C#
Processed Client SideGenerate C# classes or records from a JSON sample, with System.Text.Json or Newtonsoft attributes and nullable value types inferred.
Bookmark this tool now — skip the search next time you need it.
About JSON to C#
This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.
The JSON to C# converter turns a sample JSON payload into ready-to-use C# classes or records, so you can deserialize an API response into real types instead of digging through a dictionary. It walks the whole document: nested objects become their own types, arrays become List<T>, and numbers are mapped to int, long, or double based on the values it actually sees. Keys are converted to PascalCase properties and given the matching [JsonPropertyName] or [JsonProperty] attribute so the original wire names still bind. Choose classes or records, System.Text.Json or Newtonsoft, and an optional namespace, and paste the result straight into your project.
Key features
- Classes or records — records give you a concise immutable model, classes the familiar mutable one
- Attributes for System.Text.Json ([JsonPropertyName]) or Newtonsoft ([JsonProperty]), or none at all
- Optional file-scoped namespace declaration, with using directives added only when they are needed
- Nested objects promoted to their own sibling types, named from the key that held them
- Arrays of objects merged into one type: every element is inspected, and a field missing from some of them is marked nullable
- Numeric types chosen from the data — int, long when a value exceeds Int32 range, and double when any value is fractional
- snake_case, kebab-case, and camelCase keys converted to PascalCase properties, with collisions resolved so the output compiles
- Nullable annotations applied to value types only (int?, bool?), so the code builds whether or not nullable reference types are enabled
- Syntax-highlighted C# output and a one-click copy, generated entirely in your browser
How to use it
- Paste a representative JSON response into the input pane.
- Set the root class name, and a namespace if you want one emitted.
- Choose class or record, and the attribute style matching your serializer.
- Press Convert and read the generated types.
- Copy the code into your project and deserialize with JsonSerializer.Deserialize<Root>(json).
Tips & common mistakes
- Paste the richest sample you have. The generator can only type what it sees — a field that is null in your one sample becomes object, and an array that is empty becomes List<object>.
- For arrays, include elements that differ from each other. Every element is merged into one class, so optional fields are detected as nullable rather than being missed entirely.
- Check the numeric types before shipping. An id that happens to fit in Int32 today becomes int, so if the API can return larger values, widen it to long by hand.
- Records suit response models you never mutate and give you value equality for free. Stay with classes if you deserialize into an existing object graph or need parameterless construction.
- Attributes matter more than they look. Without them, System.Text.Json is case-sensitive by default and a user_name key will silently leave UserName null.
- A mixed-type field — sometimes a string, sometimes a number — has no single static type and comes out as object. That is usually worth fixing in the API rather than in the model.
- Working in Java instead? The JSON to Java converter uses the same analysis and emits POJOs, records, or Lombok classes with Jackson annotations.