1001Ferramentas
🔷 Converters

JSON to C# Class

Convert JSON to a C# class with auto-implemented properties. Detects primitive types, lists, arrays and nested objects. Useful for .NET/Unity. Everything in your browser.

Model an API response as .NET classes

You are about to consume an API from .NET and you need the classes that System.Text.Json or Newtonsoft will fill in. It is mechanical work, and it is exactly where the expensive mistake slips through: a money value typed as an integer, a list left out entirely. Paste a sample payload and get back a class with auto implemented properties and nested objects already split into their own classes.

Types come from values: text becomes string, true or false becomes bool, a whole number becomes long, a decimal number becomes double, null becomes object, and an array becomes a List of the first element's type. The meaningful difference from the Java generator is naming: here properties are converted to PascalCase, so first_name becomes FirstName. That matches C# convention but breaks deserialisation against snake_case JSON unless you configure something.

Before this goes into your project: if the field is money, swap double for decimal, because double rounds in binary and you do not want that on an invoice. Nullability is not annotated, so add the question mark wherever the contract allows null. Two keys with the same name at different points in the JSON produce a single class, whichever came first. An empty array becomes a List of object for lack of a sample. Conversion happens in your browser.

Frequently asked questions

How do I match properties against snake_case JSON?
On .NET 8 and later, set JsonNamingPolicy.SnakeCaseLower on the serializer. On older versions, or for irregular names, decorate each property with JsonPropertyName.
Is this usable in Unity?
Yes, these are plain POCO classes with no external dependency. If you use JsonUtility rather than Newtonsoft, convert the properties to public fields, since JsonUtility ignores properties.
What if the sample array is empty?
It becomes a List of object, because there is no element to infer from. Grab a sample with at least one item, or fix the generic parameter by hand.

Related Tools