Json Web Viewer
All tools

JSON to C# — generate C# records online

Reaching for Visual Studio's "Paste JSON As Classes"? Get the modern version of exactly that: record types with required and nullable annotations that match your document's real shape, generated in one click, entirely in your browser.

Json Web Viewer's Types mode reads your document's actual structure — property names, nesting, array element types, which fields are sometimes missing or null — and generates matching C# records, ready for System.Text.Json: init accessors, [JsonPropertyName] attributes, and #nullable enable at the top so the ? annotations actually mean something. No server round-trip, no account, no upload.

C# is the one target whose type system can express the whole story, so the output does: required says the key was present in every observed record, and ? says the value can actually be null on the C# side — because it was observed as null, or because the key is sometimes absent and deserialization would leave the property at its default. All four combinations stay distinct instead of collapsing into "probably a string".

Example — this JSON:

{
  "id": "ord_9f21a",
  "customer": {
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "vip": true
  },
  "items": [
    { "sku": "book-001", "qty": 2, "price": 19.99 },
    { "sku": "mug-014", "qty": 1, "price": 12.5 }
  ],
  "shippedAt": null
}

generates this C#:

#nullable enable

using System.Collections.Generic;
using System.Text.Json.Serialization;

public record Root
{
    [JsonPropertyName("customer")]
    public required Customer Customer { get; init; }

    [JsonPropertyName("id")]
    public required string Id { get; init; }

    [JsonPropertyName("items")]
    public required List<ItemsItem> Items { get; init; }

    [JsonPropertyName("shippedAt")]
    public required object? ShippedAt { get; init; }
}

public record Customer
{
    [JsonPropertyName("email")]
    public required string Email { get; init; }

    [JsonPropertyName("name")]
    public required string Name { get; init; }

    [JsonPropertyName("vip")]
    public required bool Vip { get; init; }
}

public record ItemsItem
{
    [JsonPropertyName("price")]
    public required double Price { get; init; }

    [JsonPropertyName("qty")]
    public required long Qty { get; init; }

    [JsonPropertyName("sku")]
    public required string Sku { get; init; }
}

Open this example in the editor →
The link above pre-loads the order example into Types mode. TypeScript is the default target — select C# from the language dropdown next to the mode buttons to regenerate the same document as records.

Frequently asked questions

Does generating C# records upload my JSON anywhere?

No. Type generation runs entirely in your browser — your JSON never leaves the page.

Why records instead of classes?

A DTO deserialized from JSON is a value, and record is C#'s word for that — value equality, with expressions, and init accessors for free. System.Text.Json binds to records without any extra configuration. If you need a mutable class, the record is a two-keyword edit away.

How are missing and null fields handled?

As two independent axes, which C# can genuinely express: required T for a key present in every record and never null, required T? for always present but sometimes null, and T? without required for a key that's sometimes absent — since a missing key leaves a property at its default, which for a reference type is null.

Need a different target language? The same dropdown also generates TypeScript, Python, Java, and Kotlin — plus Go and Rust.