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
Your JSON
C# model
How JSON values become C# types
int; long beyond ±2,147,483,647; decimal beyond the range of longdouble — and a mix of whole and decimal numbers is double tooDateTimeOffset when the values carry Z or an offset, otherwise DateTimeGuid"headquarters" becomes HeadquartersList<T> of one merged class, singularised: "companies" becomes List<Company>int?, and string? with nullable reference types onList<object> · object? — the sample does not say moreList<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.