JSON to C# Converter
Convert JSON to C# classes or records online. Infers types from a sample, adds JsonPropertyName attributes and nullable types — all in your browser.
What is the JSON to C# Converter?
The ByteTools JSON to C# Converter turns a sample JSON document into ready-to-use C# classes for System.
- Class or positional record output (C# 9+)
- [JsonPropertyName] attributes preserve the original JSON keys
- Nullable types for null values and optional keys
- List<T> for arrays, nested classes named from their keys
- Merges shapes across arrays of heterogeneous objects
- 100% private — JSON never leaves your browser
How to use the JSON to C# Converter
- 1
Paste a representative JSON sample into the input box.
- 2
Set the root class name and choose class or record output.
- 3
Click Generate C# to infer the class hierarchy.
- 4
Copy the code or download it as a .cs file.
About the JSON to C# Converter
The ByteTools JSON to C# Converter turns a sample JSON document into ready-to-use C# classes for System.Text.Json. It infers the type of every property, generates PascalCase names with [JsonPropertyName] attributes mapping back to the original keys, uses List<T> for arrays and marks nullable values with C# nullable types.
It is built for .NET developers typing an API response, building DTOs from a sample payload, or migrating hand-written models. Nested objects become their own classes named after their keys, arrays of objects are merged into a single shape, and keys missing from some elements become nullable. You can output mutable classes or immutable positional records.
Everything runs 100% locally in your browser with JavaScript. Your JSON is never uploaded, logged or stored, so it is safe to generate models from confidential API payloads and internal data structures.
Frequently asked questions
How do I convert JSON to C# classes?
Paste a JSON sample, choose a root class name and click Generate C#. The tool walks the structure, creates one class per object shape and outputs code with System.Text.Json attributes that you can copy straight into your .NET project.
Does it use System.Text.Json or Newtonsoft.Json?
The generated attributes are [JsonPropertyName], which is System.Text.Json. If you use Newtonsoft.Json, replace them with [JsonProperty] — the class structure and types stay exactly the same.
What is the difference between the class and record output?
The class output produces mutable properties with get and set, which suits most DTO scenarios. The record output produces an immutable positional record, which gives you value equality and works well for API response models you never modify.
How are null values and missing keys typed?
A property that is null in the sample, or missing from some objects in an array, is given a nullable type such as string? or int?. That way deserialization never throws when the value is absent.
When does it output int versus long or double?
Whole numbers that fit in 32 bits become int, larger ones become long, and any value with a decimal point makes the property a double. If a field mixes types across the sample, it falls back to object.
Is my JSON uploaded anywhere?
No. The conversion is plain JavaScript running in your browser tab. Nothing is transmitted or stored, so private payloads and unreleased schemas stay on your machine.
Related tools
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample online. Infers types recursively, merges array shapes and marks optional keys — 100% in your browser.
JSON to Kotlin Converter
Convert JSON to Kotlin data classes online with kotlinx.serialization or Gson annotations, nullable types and List<T> — 100% in your browser.
JSON to Rust Converter
Convert JSON to Rust structs with serde derive macros online. Generates snake_case fields, serde rename attributes, Vec<T> and Option<T> types.
JSON Formatter
Format, beautify and minify JSON online with 2-space, 4-space or tab indentation. Sort keys alphabetically and catch syntax errors instantly — free and private.
JSON Validator
Free online JSON validator: validate JSON and find syntax errors with the exact line and column. See root type, key counts and depth — instant and 100% private.