/tools/json-to-csharp
JSON to C# Converter
Generate C# 12/.NET 8 records or classes with nullable types and System.Text.Json aliases.
JSON sample
C# output
Use generated C# records to deserialize JSON
Set the root type to Account, keep System.Text.Json selected and generate from:
{"user_id":7,"roles":["reader"]}
The generated record has a long UserId property and a List<string> Roles property. Its JsonPropertyName("user_id") mapping preserves the API name. Deserialize with JsonSerializer.Deserialize<Account>(source) using the generated model.
Choose Classes in the declaration options if the project needs class declarations. Review nullable fields with responses where properties are missing or explicitly null.
/usage
Generate .NET models from JSON
- Paste representative JSON or choose a local file.
- Select records or classes and serializer-ready or framework-neutral output.
- Generate, review nullable and mixed types, then copy or download the
.csfile.
Keep a JSON key in a C# model
Generate a model from {"user-id":42} with serializer-ready output. The default record uses a UserId property and JsonPropertyName("user-id") so its JSON name is retained. Review the model against representative responses.
/output
C# models that retain JSON evidence
Modern defaults
The generator emits #nullable enable, C# records and .NET 8-friendly collection types.
Exact JSON names
[JsonPropertyName] preserves original keys when generated property names differ.
Missing and null fields
Nullable value and reference types make optional evidence visible rather than assigning unsafe defaults.
Mixed-type warning
Irreducible unions use JsonElement and surface a warning for operator review.
/faq
JSON to C# questions
Which .NET version is targeted?
The defaults target C# 12 and .NET 8 with System.Text.Json.
Does it upload the JSON?
No. Parsing, inference and C# emission happen inside a dedicated local browser worker.
Are all array items inspected?
Yes, within bounded traversal limits. Missing fields, explicit nulls and differing item types all contribute evidence.