Generate C# Classes from API Response
This example generates C# classes with JsonPropertyName attributes from a typical REST API response. The pre-filled JSON represents a user object with nested address, array of roles, and array of post objects. Switch to C# mode to see the generated classes.
What You Get
The tool produces:
- A root
Rootclass with all top-level properties RootUserclass for the nested address objectRootPostsItemclass for array items[JsonPropertyName("key")]attributes on every property- PascalCase property names following C# conventions
- Nullable types (
T?) for optional fields - C# type mappings:
string,long,double,bool,List<T>
How to Use
- The example loads with a sample API response and C# mode pre-selected
- Inspect the generated C# classes and their attributes
- Copy the classes and paste them into your C# project
- Replace with your actual API response to generate classes for your endpoints
Real-World Pattern
C# classes with JsonPropertyName attributes are the standard way to deserialize API responses in .NET. The generated code works directly with JsonSerializer.Deserialize<T>. Use nullable types for fields that may not always be present in the response.