Convert C# classes to JSON!

Paste C# class/record code and get an example JSON! Supports System.Text.Json [JsonPropertyName] and Newtonsoft.Json [JsonProperty].
C#
Result
 

Convert C# classes to JSON!

Paste C# models built from class, record or struct and get an example JSON document following System.Text.Json and Newtonsoft.Json rules. Choose between the camelCase naming policy ASP.NET Core uses by default and property names as written; names set with [JsonPropertyName] or [JsonProperty] always win.

Use it to hand a sample to a frontend or an external partner from Web API request/response models, to fill Swagger (Swashbuckle) examples, or to prepare bodies for HttpClient integration tests.

How to use

  1. Paste the model source. using, namespace, constructors and methods can remain.
  2. Choose a Naming policy: camelCase (ASP.NET Core default) for standard Web API projects, or Property names as-is if you set PropertyNamingPolicy = null or rely on Newtonsoft defaults.
  3. With Root type on Auto, the first type no other model references becomes the root; change it from the list if needed.
  4. Copy the JSON into a Swagger example, a .http file or an xUnit request body. Your option choices are saved in the URL.

Example

Input (C#)
public class InventoryItem
{
    public Guid Id { get; set; }
    public string SKU { get; set; } = "";
    [JsonPropertyName("stock_qty")]
    public int StockQuantity { get; set; }
    public StockState State { get; set; } = StockState.InStock;
    public DateTimeOffset UpdatedAt { get; set; }
    public List<string> Barcodes { get; set; } = new();
    [JsonIgnore]
    public string WarehouseNote { get; set; } = "";
    private int _version;
}

public enum StockState { InStock, LowStock, OutOfStock }
Output (JSON · camelCase)
{
  "id": "00000000-0000-0000-0000-000000000000",
  "sku": "",
  "stock_qty": 0,
  "state": 0,
  "updatedAt": "1970-01-01T00:00:00+00:00",
  "barcodes": [
    ""
  ]
}

Under the camelCase policy an all-caps name like SKU becomes sku, matching System.Text.Json's JsonNamingPolicy.CamelCase, while [JsonPropertyName("stock_qty")] keeps its name regardless of policy. WarehouseNote ([JsonIgnore]) and the private field _version are left out. The enum State has no string converter, so it shows 0, the numeric value of its initializer StockState.InStock.

Supported features

  • Renaming attributes: System.Text.Json [JsonPropertyName], Newtonsoft [JsonProperty], and [DataMember(Name = ...)].
  • Only public properties and fields are included, plus non-public members marked [JsonInclude]. static, const, [JsonIgnore] and [IgnoreDataMember] are excluded; conditional ignores such as Condition = WhenWritingNull are kept.
  • Positional records (record Customer(long Id, string Name)) and [property: JsonPropertyName(...)] targets are supported.
  • Expression-bodied computed properties (=> ...) are included, as System.Text.Json would serialize them.
  • Enums are written as numbers, as System.Text.Json and Newtonsoft do by default (explicit values like = 10 included). With [JsonConverter(typeof(JsonStringEnumConverter))] (or Newtonsoft StringEnumConverter) on the enum or the property, or [JsonStringEnumMemberName] / [EnumMember(Value = ...)] on members, the name string is used instead.
  • Dates and IDs: DateTime → 1970-01-01T00:00:00, DateTimeOffset → 1970-01-01T00:00:00+00:00, DateOnly → 1970-01-01, TimeOnly/TimeSpan → 00:00:00, Guid → all-zero GUID.
  • int?/Nullable<T> use the inner type, List<T>/IEnumerable<T>/arrays get one element, Dictionary<int, V> uses a "0" key, and object, JsonElement and JObject become null.
  • Literal initializers (= 1.5, = "KRW") are used as sample values.

Use cases

Aligning Swashbuckle examples with real responses

DTOs that mix [JsonPropertyName] with default naming make Swagger UI's generated examples easy to misread. Use this output in an ISchemaFilter or an XML <example> comment so the docs and the response share the same keys.

Moving from Newtonsoft to System.Text.Json

Switch the Naming policy back and forth on the same model to preview how key casing changes after the migration.

Checking the contract between a Unity/MAUI client and the server

When client and server keep separate copies of a model, generate JSON from each side and compare them to spot key-name mismatches quickly.

Notes and limitations

  • A JsonStringEnumConverter registered globally with AddJsonOptions in Program.cs is invisible in the model code, so enums still come out as numbers. To see names, add [JsonConverter(typeof(JsonStringEnumConverter))] to the enum declaration before pasting.
  • Nullable reference types such as string? get a typed sample, not null.
  • Custom [JsonConverter] attributes other than the enum string converter, DefaultIgnoreCondition in JsonSerializerOptions, and snake_case policies (JsonNamingPolicy.SnakeCaseLower) are not applied.
  • Polymorphism via [JsonPolymorphic]/[JsonDerivedType] is not supported; only the declared base type is generated.

FAQ

When should I use each Naming policy option?

ASP.NET Core Web API uses JsonSerializerDefaults.Web, which is camelCase. A console app calling JsonSerializer.Serialize without options, or default Newtonsoft.Json settings, keeps property names, so choose Property names as-is there.

Why does a computed property like public string FullName => ... appear?

Both System.Text.Json and Newtonsoft.Json serialize public properties with a getter, so computed properties end up in responses too. Add [JsonIgnore] if you don't want them exported.

[JsonPropertyName] on a record's positional parameter doesn't rename the key at runtime.

Without a target, the compiler applies the attribute only to the constructor parameter. This tool recognizes both forms, but to rename the serialized property reliably write [property: JsonPropertyName("...")].

Why is there no Z on DateTime values?

A DateTime with DateTimeKind.Unspecified serializes without an offset. If you need an explicit UTC offset, DateTimeOffset produces the +00:00 form.