JSON to C# Class
Paste JSON and get C# classes with typed properties for every nested object, ready to deserialize in .NET. Free, no signup, and generated in your browser so nothing is uploaded.
16 lines · processed in your browser, nothing is uploaded
C# output · Root.cs
Generated code appears here.Example: JSON to C#
This JSON sample, with the root type named User, produces the C# below using the default options.
{
"id": 1024,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"score": 98.5,
"tags": [
"admin",
"beta"
],
"address": {
"city": "London",
"postcode": "NW1 6XE"
}
}namespace Example
{
using System.Collections.Generic;
public partial class User
{
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public bool Active { get; set; }
public double Score { get; set; }
public List<string> Tags { get; set; }
public Address Address { get; set; }
}
public partial class Address
{
public string City { get; set; }
public string Postcode { get; set; }
}
}
How to convert JSON to C#
- 1Paste a JSON object or array into the input.
- 2Select C# as the output language.
- 3Name the root class, for example Invoice.
- 4Adjust options such as namespace or serialization framework if available.
- 5Copy the classes into a .cs file in your project.
Mapping names with System.Text.Json
C# properties are PascalCase while JSON keys are often camelCase or snake_case. Put [JsonPropertyName("user_id")] on a property to bind it to an exact key, or set JsonSerializerOptions.PropertyNamingPolicy for a whole payload.
Deserialize with JsonSerializer.Deserialize<Invoice>(json, options). System.Text.Json is case-sensitive by default; set PropertyNameCaseInsensitive = true if the casing is inconsistent.
System.Text.Json or Newtonsoft.Json?
System.Text.Json ships with .NET and is the default in ASP.NET Core. Newtonsoft.Json uses [JsonProperty] instead of [JsonPropertyName] and is more lenient, which helps with older or irregular APIs.
The attributes differ between the two, so make sure the generated attributes match the library you actually reference.
Nullable types
With nullable reference types enabled, mark properties that can be missing or null as string? or Address?. Value types need the same treatment: int? and DateTime? for fields that may be absent.
Collections are usually best initialized to empty lists so callers do not need null checks.