MagmaNex LogoMagmaNex

JSON to C# Class

Generate C# classes from JSON

What does this tool do?

JSON to C# generates System.Text.Json-ready C# classes from a sample JSON. For .NET developers it is a fast way to turn API responses or config files into strongly typed models without writing them by hand, and you can name the root class yourself.

How to use it

  1. Paste or type your data into the left field.
  2. The result is generated instantly on the right.
  3. Use the Copy button to grab the output.

Type inference and property naming

The tool inspects each value and picks a suitable C# type: whole numbers become int, decimals become double, true/false become bool, and text becomes string. JSON keys are converted to PascalCase property names, and snake_case keys such as first_name are joined into FirstName. The original key is preserved with a [JsonPropertyName] attribute above each property so serialization keeps working. The result is code you can compile straight away.

Nested objects and arrays

Every nested object becomes its own class, named after the property it belongs to. Arrays are modeled as List<T>, with the element type inferred from the first item; empty arrays become List<object>. Null values are marked as object?. The output starts with a using System.Text.Json.Serialization line so you can paste the classes into your project and use them immediately without extra edits.

Frequently asked questions

Which serializer is the code built for?

Modern .NET's built-in System.Text.Json. Each property carries a [JsonPropertyName] attribute, so you do not need a separate Newtonsoft.Json package.

Are numbers always typed correctly?

Types are inferred from the sample value: 30 becomes int, 30.5 becomes double. If a field can be both whole and fractional, use a decimal value in your sample JSON to be safe.

Can I rename the root class?

Yes, type any name in the 'Class name' field. Nested classes are named after that root and the corresponding property names.

Is JSON to C# Class free?

Yes. JSON to C# Class and all 300+ tools on MagmaNex are completely free with no signup or account required.

Is my data safe?

Yes. Everything runs locally in your browser. The data you enter is never sent to a server, stored, or shared.

Does it work on mobile?

Yes. JSON to C# Class works on phones, tablets and desktops — no app download needed.

🔒 Privacy: everything runs in your browser, your data is never sent to a server.

Related Tools

📝 Related Articles

Popular Tools