JSON to C# Converter
JSON Input
C# Output
Paste your JSON on the left and the C# code shows up here.
Or drop a file on this box, , or .
What do the generated C# classes look like?
Matching an API response by hand means typing twenty properties and getting one casing wrong. Here you paste the JSON and get a C# class for every object, PascalCase properties, and a [JsonPropertyName("invoiceNo")] attribute on each one. Keep those attributes: a plain JsonSerializer.Deserialize call in System.Text.Json compares names case-sensitively, so without them a camelCase payload leaves every property at its default value.
Each array becomes List<T> and an array of arrays List<List<T>>. All elements are read, so a discountPct that only the second invoice line carries still gets a property. Integers start at int, move to long or ulong past 32 bits and to decimal beyond 64. Fractional numbers become double, so for money you will usually change AmountDue to decimal yourself. Two objects with the same key name, say a top-level address and billing.address, get separate classes (Address and BillingAddress), and an empty {} turns into Dictionary<string, object>.
Two switches change the shape. Nullable Types puts #nullable enable at the top and a ? on anything the sample showed as null or absent, so that optional discount becomes int?. Switching Use Properties off gives plain public fields in place of { get; set; }, each marked [JsonInclude] because System.Text.Json skips public fields without it. A key that was null every time, like an unset approvedBy, comes out as object?; give it a real type once you have seen it filled in. The classes are built by script on this page, and nothing is posted anywhere.
How to use it
The output updates a moment after you stop typing, so there's no Convert button.
Paste JSON or upload a file
Drop JSON into the JSON Input panel, or load it from disk with Upload (.json and .txt both work). Sample gives you a subscriber with an account and a device list. A usage record off a billing feed works just as well:
{"subscriberId":"SUB-7731","msisdn":"447700900123","dataUsage":12.75,"roaming":true,"apn":"internet.eir.ie"} The Class Name box names the root class. Paste an array of objects and that name goes on the item class, with a first line such as // The JSON root is an array: deserialize it as List<Invoice>. when you typed Invoice.
Read the classes
The C# Output panel starts with the using lines it needs, then the classes, with nested ones first. The example above gives public string SubscriberId { get; set; }, public double DataUsage { get; set; } and so on, each with its JSON name in an attribute.
Copy or download
Copy puts the code on your clipboard and Download saves a .cs file. Then deserialize with JsonSerializer.Deserialize<RootObject>(json).
Where this saves time
Typed HttpClient calls
Grab a response from the API you're integrating with, generate the model, and call GetFromJsonAsync<Order>() instead of picking values out of a JsonDocument.
Webhook payloads
Payment and shipping providers post JSON with dozens of fields and odd key names like event-type. The attribute keeps the original key, so the property can still be called EventType.
Options classes for appsettings.json
Paste a section of your config and get a class to bind with the options pattern. Configuration binding matches property names case-insensitively and ignores the attributes, so they do no harm there.
Test fixtures
Turn a captured JSON fixture into classes so your tests can assert on order.Customer.Email instead of string-matching JSON.
Common questions
Does this work with Newtonsoft.Json?
Mostly. Newtonsoft.Json matches property names case-insensitively, so the classes deserialize fine for ordinary camelCase keys, but it ignores [JsonPropertyName]. For keys like first name or user-id, swap the attribute for Newtonsoft's [JsonProperty("user-id")].
Why does a property end in Value?
The compiler refuses a member named like the class around it (error CS0542). So {"address": {"address": "12 Quay St"}} gives an Address class whose inner property is AddressValue, still tagged [JsonPropertyName("address")] so binding works. A key starting with a digit, such as 2fa, becomes _2fa for the same kind of reason.
How are big numbers typed?
The page reads integers without rounding them, then picks int, long, ulong or decimal depending on the largest value it sees. An ICCID like 8901240544102066246 gets long.
What if the root isn't an object?
For null, a string, a number, an empty array or an array of plain values there's nothing to turn into a class, so the output panel explains that instead of showing empty code.
Do I need C# 8 for the nullable output?
Yes, #nullable enable and nullable reference types (string?) need C# 8 or later. Turn Nullable Types off for older projects. You may still see CS8618 warnings for non-nullable properties without initializers; add required or default values as suits your code.
Is my JSON uploaded?
No. The generator ships inside this page and runs when you stop typing; no request goes out with your JSON. Paste a few array items rather than a full export, since anything over 256 KB is turned away with an "Input too large" note.
Other Code Generation Tools
When the same JSON also feeds a TypeScript client, a Java service or a Go worker, these pages write the matching types for each: