C# to JSON Sample Generator
Paste a C# class or record definition to generate a realistic sample JSON payload matching its shape — the reverse of the JSON to C# Class Generator.
What this tool does
Paste a C# class or record definition and get a realistic sample JSON payload matching its shape — the reverse of the JSON to C# Class/Record Generator. Property types map to plausible sample values (an int named Id becomes 1, a string named Email becomes "[email protected]"), nested locally-defined types become nested JSON objects, and List<T> properties become a 2-item array. It runs entirely within your active Blazor Server session using a hand-written tokenizer — no Roslyn or compiler dependency — and your code is never sent to a separate API.
Worked example
This C#:
public class Order
{
public int Id { get; set; }
public string CustomerEmail { get; set; }
public decimal Total { get; set; }
public bool IsPaid { get; set; }
public DateTime CreatedAt { get; set; }
public List<OrderItem> Items { get; set; }
}
public class OrderItem
{
public string Sku { get; set; }
public int Quantity { get; set; }
}
produces:
{
"Id": 1,
"CustomerEmail": "[email protected]",
"Total": 149.99,
"IsPaid": true,
"CreatedAt": "2026-08-01T12:00:00Z",
"Items": [
{ "Sku": "ABC123", "Quantity": 3 },
{ "Sku": "ABC124", "Quantity": 4 }
]
}
The nested OrderItem class — declared separately below Order — is resolved automatically because List<OrderItem> names a type this tool also found in the pasted input. Only the first declared type becomes the root JSON object; every other declared type is treated purely as a nested-type definition to resolve properties against, the same one-root convention the JSON to C# generator uses in reverse.
How sample values are chosen
- Numbers — a property literally or conventionally named
Idgenerates1;Count/Quantity-style names generate3; everything else generates42.decimal/double/floatproperties named likePrice,Total,Amount, orCostgenerate149.99; others generate9.99. - Strings — name-based heuristics cover common cases:
Email→ a sample email address,Url/Uri→ a sample URL,Phone→ a sample phone number,Name→ a sample name,Address/City/Country→ sample location text,Status→"Active", anything ending inCodeorSku→ an alphanumeric code. Everything else falls back to"Sample <PropertyName>". bool— names starting withIs/Has/Canfollowed by a negative-sounding word (Deleted,Archived,Disabled,Cancelled,Expired) generatefalse; everything else generatestrue.DateTime/DateTimeOffset— a fixed sample timestamp, so output stays stable across runs rather than depending on when you happened to click Generate.Guid— a fixed, recognizable sample GUID (the same one used in ASP.NET Core's own Swagger/OpenAPI example generation).List<T>— always exactly 2 items, with number-based values incrementing between the two so the array doesn't look like a single value duplicated.
Nullable annotations and JSON attributes
A trailing ? on a property's type (string?, int?, a nullable nested type) is recognized and stripped before choosing a sample value — this generator always populates nullable properties with a real value rather than null, since a fully populated example is more useful as a sample payload than one full of nulls. A [JsonPropertyName("custom_key")] attribute directly above a property always wins as the JSON key, overriding both the property's own name and the camelCase toggle — matching exactly how System.Text.Json itself resolves naming precedence at runtime.
What isn't guessed
A property whose type isn't a recognized primitive (string, int, long, short, byte, decimal, double, float, bool, DateTime, DateTimeOffset, Guid), a List<T>/IEnumerable<T>/ICollection<T> of one, or another type declared in the same pasted input, is generated as JSON null and listed in a warning below the output — rather than guessing a shape for a type this tool has never seen the definition of.
How to use this tool
- Paste one or more C#
class/recorddeclarations — the first one becomes the JSON root. - Toggle camelCase naming policy if your API serializes with
JsonNamingPolicy.CamelCase(the ASP.NET Core default). - Click Generate (or Ctrl+Enter).
- Review the warning list, if any, for properties that came back
nullbecause their type wasn't recognized.
C# class or record
public class Order
{
public int Id { get; set; }
public string CustomerEmail { get; set; }
public decimal Total { get; set; }
public bool IsPaid { get; set; }
public DateTime CreatedAt { get; set; }
public List<OrderItem> Items { get; set; }
}
public class OrderItem
{
public string Sku { get; set; }
public int Quantity { get; set; }
}Sample JSON
JSON output