You are offline. Tools you have opened before keep working.
JSON to C# classes
Paste JSON and get C# classes or records with properties, List<T> collections and nullable types. JsonPropertyName or JsonProperty attributes keep the original JSON keys.
Free and private. Everything runs in your browser, nothing is uploaded.
Report a problem
How it works
Paste your JSONPaste a response from your API or open a .json file. Use Sample to see an example.
Adjust the optionsSet the name of the top level type and the options for this language. The code updates as you type.
Copy or downloadCopy the code into your project or download it as a file.
Ready for System.Text.Json and Newtonsoft
Properties are written in PascalCase. System.Text.Json matches property names case sensitively by default, so the generator adds a JsonPropertyName attribute whenever the C# name differs from the key. With Newtonsoft.Json, which ignores case, the attribute is only added when the name really changes, for example user_name to UserName.
Optional and null fields become nullable types such as int? or string?, which fits projects with nullable reference types turned on. Required strings and lists can start with an empty value so the compiler does not warn. Whole numbers above the 32 bit range become long, ISO dates become DateTime or DateTimeOffset when they carry a time zone.
Frequently asked questions
Class or record?
Records give value equality and init only properties, which suits data transfer objects. Classes with get and set are the classic choice and work with every serializer and older .NET versions.
Is my JSON uploaded anywhere?
No. The types are generated in your browser. API responses with customer data or keys never leave your device.
How are optional fields detected?
If the JSON contains a list of objects, every object is compared. A field that is missing from at least one object is marked optional. With a single object, every field is treated as required.
What happens with fields that are always null?
The type cannot be known from the sample, so the field gets a general type such as unknown, object, Any or JsonElement. Add a sample where the field has a value to get a precise type.
Why is my 1.0 typed as a decimal number?
The tool looks at how the number is written. 1.0 or 2.5 become double or float, 1 becomes an integer. If a field is whole in some items and decimal in others, the decimal type is used.
Can I use the result in production code?
Yes, the code compiles as it is in the usual setups. Review names and types before you commit it, because a sample can never show every possible value.
Does it work offline?
Yes. After you open the page once, it keeps working without an internet connection.