Skip to content
Browse tools

JSON → C#

Paste a JSON response and get C# classes you can deserialise straight into — every array item is read, so keys that only some items have become nullable, nested objects become their own types, and dates and GUIDs are typed as DateTime and Guid.

Emits
class · record
Attributes
System.Text.Json · Newtonsoft
Runs
in your browser
Step 1

Your JSON

empty
drop a .json file to load it
Step 2

C# model

Emit
Lists Mixed
Attributes
Options
empty
Nothing to convert yet Paste JSON on the left, open a .json file, or load the sample.

How JSON values become C# types

In the JSONIn the C#
42int; long beyond ±2,147,483,647; decimal beyond the range of long
4.5 · 1.0 · 1e3double — and a mix of whole and decimal numbers is double too
"2025-11-02T09:30:00Z"DateTimeOffset when the values carry Z or an offset, otherwise DateTime
"b3c1f0a2-7d4e-…"Guid
{ … }A class named after the key: "headquarters" becomes Headquarters
[ { … }, { … } ]List<T> of one merged class, singularised: "companies" becomes List<Company>
null · key sometimes missingNullable: int?, and string? with nullable reference types on
[] · only ever nullList<object> · object? — the sample does not say more
[1, "two", true]List<JsonElement> (or object; JToken with Newtonsoft)

Worth knowing

Every array item is read, not just the first

Fifty objects in an array become one class with every key any of them had. A key that is missing from some items, or null in some, is made nullable — which is exactly where a model generated from the first item alone throws at runtime.

Why the attributes are there

System.Text.Json matches names case-sensitively unless you configure it otherwise, so Name would not pick up "name". Every property whose C# name differs from its JSON key gets [JsonPropertyName], which also covers keys like "first-name", "2fa" or "@odata.context" that cannot be C# names at all.

DateTime or DateTimeOffset

If any value for a property carries Z or an offset such as +05:30, it becomes DateTimeOffset so the offset is never thrown away; values without one become DateTime. Only the ISO 8601 form System.Text.Json accepts is detected — a space instead of the T stays a string.

Nullable, required and initialisers

With nullable reference types on, non-null strings and lists get = string.Empty and = [] so the compiler has nothing to warn about. Turn on required instead and keys present in every sample must be in the JSON — System.Text.Json in .NET 8 enforces it. The output targets C# 12.

Identical shapes share one class

billingAddress and shippingAddress with the same keys produce one class, used by both. Two different shapes that both want the name Item become Item and Item2 rather than silently colliding.

Nothing is uploaded

The JSON is parsed and the classes are written by JavaScript in this tab. API responses often carry tokens and customer data, which is exactly what should not be pasted into someone else's server.