Output will appear here
Output will appear here
Paste JSON and this tool writes C# classes you can pass straight to JsonSerializer.Deserialize<Root>(). Each property gets a PascalCase name plus a [JsonPropertyName] attribute holding the original key, so camelCase and snake_case APIs bind without a naming policy. The file starts with #nullable enable, so null values and missing keys become T?. ISO timestamps become DateTime.
By Ankit Aglawe · Updated · Runs entirely in your browser
Each nested object becomes its own class, named after its key (Customer, Metadata). created is a full ISO 8601 timestamp, so it is typed DateTime and the generator adds using System;. Amounts in cents stay int.
{
"id": "pi_3PqL2x",
"amount": 4999,
"currency": "usd",
"captured": true,
"created": "2024-09-12T08:45:10Z",
"customer": { "id": "cus_Q81", "email": "[email protected]", "name": "Lena Ortiz" },
"metadata": { "orderRef": "WEB-20931" }
}#nullable enable
using System;
using System.Text.Json.Serialization;
public class Customer
{
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
}
public class Metadata
{
[JsonPropertyName("orderRef")]
public string OrderRef { get; set; }
}
public class Root
{
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("amount")]
public int Amount { get; set; }
[JsonPropertyName("currency")]
public string Currency { get; set; }
[JsonPropertyName("captured")]
public bool Captured { get; set; }
[JsonPropertyName("created")]
public DateTime Created { get; set; }
[JsonPropertyName("customer")]
public Customer Customer { get; set; }
[JsonPropertyName("metadata")]
public Metadata Metadata { get; set; }
}All three records are merged into one class. managerId is null in one record, so it is int?. remote appears only once, so it is bool?. salary mixes whole and decimal values, so it is double. The comment at the end tells you to deserialize into List<Root>.
[
{ "employeeId": 1201, "fullName": "Priya Nair", "department": "Platform", "salary": 98500.0, "managerId": null, "skills": ["Go", "Kubernetes"] },
{ "employeeId": 1202, "fullName": "Tom Becker", "department": "Payments", "salary": 87250.5, "managerId": 1201, "skills": [] },
{ "employeeId": 1203, "fullName": "Mei Chen", "department": "Platform", "salary": 105000, "managerId": 1201, "skills": ["C#"], "remote": true }
]#nullable enable
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Root
{
[JsonPropertyName("employeeId")]
public int EmployeeId { get; set; }
[JsonPropertyName("fullName")]
public string FullName { get; set; }
[JsonPropertyName("department")]
public string Department { get; set; }
[JsonPropertyName("salary")]
public double Salary { get; set; }
[JsonPropertyName("managerId")]
public int? ManagerId { get; set; }
[JsonPropertyName("skills")]
public List<string> Skills { get; set; }
[JsonPropertyName("remote")]
public bool? Remote { get; set; }
}
// Root type: List<Root>Every code generator on this site is run on the same awkward input: a 64-bit id, a float written as 1.0, a null, a date string, a reserved word as a key, an empty array, a nested array and an array of objects whose keys differ. This is the exact output for C#, generated when the page was built.
{
"id": 9007199254740993,
"price": 19.99,
"ratio": 1.0,
"deleted_at": null,
"created_at": "2024-01-15T10:30:00Z",
"class": "premium",
"tags": [],
"matrix": [[1, 2], [3, 4.5]],
"items": [{ "sku": "A1", "qty": 1 }, { "sku": "B2", "qty": 2, "note": "gift" }]
}#nullable enable
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Item
{
[JsonPropertyName("sku")]
public string Sku { get; set; }
[JsonPropertyName("qty")]
public int Qty { get; set; }
[JsonPropertyName("note")]
public string? Note { get; set; }
}
public class Root
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("price")]
public double Price { get; set; }
[JsonPropertyName("ratio")]
public int Ratio { get; set; }
[JsonPropertyName("deleted_at")]
public object? DeletedAt { get; set; }
[JsonPropertyName("created_at")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("class")]
public string Class { get; set; }
[JsonPropertyName("tags")]
public List<object> Tags { get; set; }
[JsonPropertyName("matrix")]
public List<List<double>> Matrix { get; set; }
[JsonPropertyName("items")]
public List<Item> Items { get; set; }
}A field that is sometimes null becomes a nullable type, such as int? or string?. A field that is null in every sample, like deleted_at above, gives no hint of its real type, so it is typed object?. Paste a sample where it has a value and the type narrows.
A whole number is typed int while every sampled value fits in 32 bits and long once one does not, so the id above, far beyond int.MaxValue, is long. System.Text.Json throws a JsonException when a value overflows an int, so widen ids by hand if your sample happens to only hold small ones. The browser also reads 1.0 as the integer 1, so ratio comes out int. If the real API sends 1.0, System.Text.Json will not put it in an int; switch the property to double.
A key present in only some array items gets a ? on its type, the same as a null value. In the edge-case output, note is string? because the first item has no note. C# has no separate "absent" state, so both cases land on null after deserializing.
Keys become PascalCase properties, so class becomes Class and no @ escape is needed. The JSON name always survives in [JsonPropertyName]. If a key turns into the same name as its class, for example a root key inside Root, the property gets a Value suffix to avoid compiler error CS0542.
A string that is a full ISO 8601 date-time, such as 2024-01-15T10:30:00Z, becomes DateTime. A date without a time (2024-01-15) stays string; change it to DateOnly yourself if you are on .NET 6 or later.
Arrays become List<T>. An empty array has no element type, so tags is List<object>. Nested arrays nest the list: matrix holds 1, 2 and 4.5, so it is List<List<double>>. An array of objects shares one class across all its items.
Because the file turns on nullable reference types, non-nullable string and class properties without an initializer raise warning CS8618. It is a warning, not an error. Add the C# 11 required modifier or = default!; if your build treats warnings as errors.
| JSON value | C# type | Notes |
|---|---|---|
| string | string | |
| ISO 8601 date-time string | DateTime | Date-only strings stay string |
| whole number | int or long | long when a value exceeds 2,147,483,647 |
| number with a fraction | double | Also when mixed with whole numbers |
| true / false | bool | |
| null | T? | object? if never seen with a value |
| key missing in some objects | T? | |
| object | public class Name | Named after its key |
| array | List<T> | Empty array is List<object> |
| mixed types | object |
Enter a JSON object or array in the editor. Complex structures with nested objects, arrays, and mixed types are all supported.
The output shows C# classes with auto-properties and JsonPropertyName attributes for System.Text.Json serialization.
Copy the classes or download a .cs file ready to add to your .NET project. Works with .NET 6+ and System.Text.Json out of the box.
Paste the JSON on the left and copy the classes from the right. Then call JsonSerializer.Deserialize<Root>(json). For a top-level array, deserialize into List<Root>.
The attributes are System.Text.Json [JsonPropertyName]. For Json.NET, replace them with [JsonProperty("...")] and change the using to Newtonsoft.Json. The class shape is the same.
When any value of that field in your sample is above 2,147,483,647 or below its negative. Otherwise it is int, so if ids or millisecond timestamps in your sample are small but can grow, change the property to long.
No. It writes classes with { get; set; } auto-properties, which every serializer and model binder supports. You can turn them into records by hand if you want immutability.
Both become nullable types (string?, int?) under #nullable enable. A field that is always null becomes object?.
No. The classes are generated by JavaScript in your browser and nothing is sent to a server.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.