Every .NET developer has been there: you get a JSON payload from an API, and now you need a strongly-typed C# class to deserialise it into. Writing it by hand is tedious, error-prone, and wastes time you could spend on actual logic. The Dev Cosmos JSON → C# tool eliminates this toil entirely.
What Is a POCO Class?
POCO stands for Plain Old CLR Object. It's a simple C# class with public properties and no framework dependencies — the standard way to model JSON data in .NET. When you call JsonConvert.DeserializeObject<MyClass>(json) (Newtonsoft) or JsonSerializer.Deserialize<MyClass>(json) (System.Text.Json), you're deserialising into a POCO.
The Boilerplate Problem
Given this JSON from a typical e-commerce API:
{
"orderId": 10042,
"customer": {
"id": 7,
"name": "Alice Johnson",
"email": "alice@example.com"
},
"items": [
{ "sku": "WIDGET-001", "qty": 2, "price": 19.99 }
],
"total": 39.98,
"placedAt": "2025-06-15T14:30:00Z",
"isPaid": true
}
Writing the C# model classes by hand — with correct types, proper PascalCase names, JSON attributes, and nullable annotations — would take 10–15 minutes. The generator does it in under a second.
Using the Generator
- Paste your JSON into the input panel
- Set the Root class name (e.g.
OrderResponse) - Toggle your preferred options using the switches
- Copy the generated C# output
Available Options
| Option | What it does |
|---|---|
Namespace | Wraps all classes in a namespace GeneratedModels { } block |
JsonProperty attrs | Adds [JsonProperty("camelCaseName")] so Newtonsoft maps correctly |
Nullable types | Appends ? to value types (e.g. int?, bool?) for nullable safety |
XML docs | Adds /// <summary> comments to each class |
Understanding the Generated Output
For the order JSON above with all options enabled, the generator produces:
using Newtonsoft.Json;
namespace GeneratedModels
{
/// <summary>Represents a OrderResponse object.</summary>
public class OrderResponse
{
[JsonProperty("orderId")]
public int OrderId { get; set; }
[JsonProperty("customer")]
public Customer Customer { get; set; }
[JsonProperty("items")]
public List<Items> Items { get; set; }
[JsonProperty("total")]
public double Total { get; set; }
[JsonProperty("placedAt")]
public DateTime PlacedAt { get; set; }
[JsonProperty("isPaid")]
public bool IsPaid { get; set; }
}
public class Customer
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
}
}
DateTime from ISO 8601 strings, int vs double from numbers, and generates List<T> for arrays. No manual type assignment needed.PascalCase Conversion
JSON properties are almost always camelCase while C# properties use PascalCase by convention. The generator handles this automatically: orderId → OrderId, firstName → FirstName, is_active → IsActive.
The [JsonProperty] attribute preserves the original JSON name for serialisation, so round-trip accuracy is guaranteed.
Nested Objects and Arrays
The generator recurses into nested objects and arrays of objects, producing a separate class for each unique object shape. Nested objects become named classes based on their property key — "customer": {...} generates a Customer class, "items": [{...}] generates an Items class and types the property as List<Items>.
List<object>. For best results, ensure your sample JSON has representative values in each array.Adapting to System.Text.Json
The generator outputs Newtonsoft-style [JsonProperty] attributes. If you're using System.Text.Json (the modern .NET default), swap the attribute:
// Newtonsoft.Json
[JsonProperty("orderId")]
public int OrderId { get; set; }
// System.Text.Json
[JsonPropertyName("orderId")]
public int OrderId { get; set; }
Best Practices After Generating
- Review all
objecttypes — these are the generator's way of saying "I couldn't infer this." Replace them with the correct type once you know what the field contains. - Enable nullable reference types in your
.csproj(<Nullable>enable</Nullable>) and add?to properties that can be null. - Rename
Itemsclasses to be more descriptive —Items→OrderLineItemmakes the model self-documenting. - Consider records for immutable models in C# 9+: change
public class Foo { get; set; }topublic record Foo(...);.
null in your sample but is actually a string in real responses, the generator will type it as object. Use a representative payload with populated values for best results.Recommended Workflow
- Make the API call in your browser's DevTools or Postman and copy the raw response body
- Paste into the JSON → C# tool and set the root class name to match the response concept
- Enable Namespace, JsonProperty attrs, and Nullable types
- Copy the output and create a new
Models/file in your project - Rename generic class names (
Items→Product) for clarity