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.

By Pankaj Kumar · DevToolsHub · Last updated Aug 2026

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 Id generates 1; Count/Quantity-style names generate 3; everything else generates 42. decimal/double/float properties named like Price, Total, Amount, or Cost generate 149.99; others generate 9.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 in Code or Sku → an alphanumeric code. Everything else falls back to "Sample <PropertyName>".
  • bool — names starting with Is/Has/Can followed by a negative-sounding word (Deleted, Archived, Disabled, Cancelled, Expired) generate false; everything else generates true.
  • 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

  1. Paste one or more C# class/record declarations — the first one becomes the JSON root.
  2. Toggle camelCase naming policy if your API serializes with JsonNamingPolicy.CamelCase (the ASP.NET Core default).
  3. Click Generate (or Ctrl+Enter).
  4. Review the warning list, if any, for properties that came back null because their type wasn't recognized.
This tool is built with ASP.NET Core 8, Blazor Server, and System.Text.Json.Nodes and a hand-written regex-based C# property parser (no Roslyn/compiler dependency). It runs securely on Microsoft Azure.
Input Section

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; }
}
Output Section

Sample JSON

JSON output