How to convert JSON to C#
- Paste your JSON into the left panel, or click Load Sample.
- C# is already selected as the output on the right.
- Click Convert, then Copy Output.
Example
This JSON:
{ "id": 101, "name": "Ada Lovelace", "email": "ada@example.com", "active": true, "balance": 250.75,
"address": { "city": "London", "postcode": "N1 9GU" }, "tags": ["admin", "beta"] } becomes:
using System.Collections.Generic;
public class Address
{
public string City { get; set; }
public string Postcode { get; set; }
}
public class RootObject
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public bool Active { get; set; }
public double Balance { get; set; }
public Address Address { get; set; }
public List<string> Tags { get; set; }
} How JSON types map to C#
| JSON value | C# type |
|---|---|
"text" | string |
101 | int |
250.75 | double |
true | bool |
{ … } | a new class named after the key |
["a", "b"] | List<string> |
Deserializing the JSON
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var root = JsonSerializer.Deserialize<RootObject>(json, options); The properties are PascalCase, as C# style expects, while JSON keys are usually camelCase. ASP.NET Core handles that automatically; on your own, set PropertyNameCaseInsensitive as above or JsonNamingPolicy.CamelCase. With Newtonsoft.Json, JsonConvert.DeserializeObject<RootObject>(json) matches case-insensitively by default.
Things to check after generating
- Rename
RootObjectand add a namespace. - Use
decimalfor money andlongfor large IDs. - With nullable reference types enabled, mark optional properties as
string?or initialise them. - For immutable DTOs on C# 9+, you can turn the classes into
recordtypes.
Is my JSON sent anywhere?
Your JSON is sent to our server, converted in memory and returned; it isn't stored. See the privacy policy.
Frequently asked questions
How do I convert JSON to a C# class?
Paste the JSON on the left, keep C# selected on the right and click Convert. Copy the classes into your project and deserialize with JsonSerializer.Deserialize.
Why are the property names PascalCase?
That is the C# convention. Use case-insensitive matching or a camelCase naming policy so they still map to camelCase JSON keys.
Does it work with Newtonsoft.Json?
Yes. The classes are plain properties, so both System.Text.Json and Newtonsoft.Json can read them.
Does it handle nested objects?
Yes. Each nested object becomes its own class and arrays become List properties.
Other languages: JSON to Java · JSON to TypeScript · JSON to Go · JSON to Python · JSON to Kotlin · all languages