JSON to C#
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
JSON to C#
Paste a JSON sample, such as an API response, and Bracely writes C# classes for System.Text.Json for it. Each object becomes a C# class with [JsonPropertyName] attributes, so the original key names round-trip.
Example: an order for an ASP.NET Core API
An order from a storefront API with a nested address and line items. Properties are PascalCase with [JsonPropertyName] so the JSON names still match, the lines array becomes List<Line> with a class named in the singular, and discount, in only one line, becomes a nullable long?:
Input
{
"orderId": "ORD-20419",
"placedAt": "2026-10-29T10:00:00Z",
"shipping_address": {
"city": "Pune",
"pin": "411001"
},
"lines": [
{
"sku": "KB-01",
"qty": 1,
"unit_price": 2499,
"discount": 250
},
{
"sku": "MS-02",
"qty": 2,
"unit_price": 799
}
],
"paid": true
}Output
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Order
{
[JsonPropertyName("orderId")]
public string OrderId { get; set; } = default!;
[JsonPropertyName("placedAt")]
public string PlacedAt { get; set; } = default!;
[JsonPropertyName("shipping_address")]
public ShippingAddress ShippingAddress { get; set; } = default!;
[JsonPropertyName("lines")]
public List<Line> Lines { get; set; } = default!;
[JsonPropertyName("paid")]
public bool Paid { get; set; }
}
public class ShippingAddress
{
[JsonPropertyName("city")]
public string City { get; set; } = default!;
[JsonPropertyName("pin")]
public string Pin { get; set; } = default!;
}
public class Line
{
[JsonPropertyName("sku")]
public string Sku { get; set; } = default!;
[JsonPropertyName("qty")]
public long Qty { get; set; }
[JsonPropertyName("unit_price")]
public long UnitPrice { get; set; }
[JsonPropertyName("discount")]
public long? Discount { get; set; }
}
How do I use the JSON to C#?
- Paste a JSON sample.
- Set the root type name, for example Order.
- Copy the C# code into your project.
What does the JSON to C# do?
- Properties in PascalCase with [JsonPropertyName]
- Nullable types for fields that can be missing
- List<T> for arrays
- Nested objects become their own named types
- 20 other languages from the same sample, including TypeScript
When to use the JSON to C#
ASP.NET Core APIs, Blazor apps, Azure Functions and MAUI apps all deserialize JSON into classes. Generating them from a real response saves writing every property and keeps the JSON names exact, which matters as soon as the API uses snake_case or names that clash with C# conventions.
Each object becomes a class with PascalCase properties and [JsonPropertyName] for System.Text.Json, so OrderId still reads "orderId" and ShippingAddress reads "shipping_address". Whole numbers become long and decimals double; values that can be null or missing become nullable (long?, string?); and lists become List<T> with the class named in the singular. Non-nullable reference properties are initialised with default! so the code compiles cleanly with nullable reference types on. Omit when empty adds [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] to the fields you list, or to all of them with *.
Frequently asked questions
- Does it work with Newtonsoft.Json?
- The classes are plain, so yes, but the attributes are System.Text.Json's. With Newtonsoft, replace [JsonPropertyName("x")] with [JsonProperty("x")], or set a naming policy and drop them.
- Why default! on properties?
- With nullable reference types enabled, a non-nullable string must be set before use. default! tells the compiler the deserializer will fill it, without changing behaviour.
- How does it pick C# types?
- From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
- Can I generate other languages?
- Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, Kotlin, Swift, Rust, Scala, Ruby, Dart, PHP, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 108 JSON tools in one page. Related ones:
- JSON to Python
- JSON to Kotlin
- JSON to Swift
- JSON to Dart
- JSON to Rust
- JSON to PHP
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- JSON to Pydantic
- JSON to TypeBox
- JSON to Valibot
- JSON to Yup
- JSON to Prisma
- JSON5 / JSONC to JSON
- JSON to SQL
- Edge-case test data
- Password generator
- TypeScript formatter
- Code screenshot
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram