Generate C# Models from Complete JSON Examples
Infer C# classes locally with exact JSON property names, JsonRequired presence and explicit nullable and raw-number capabilities.
Tool workspace
JSON to C#
C# 12 / .NET 8; System.Text.Json and standard library only.
JsonRequired enforces presence, not nonnull references. Optional nullable properties, including JsonElement?, collapse absence and null. Integer lexemes in int64 range without negative zero use long; other numbers use JsonElement. Root helpers deserialize without validating the inferred contract. Isolated surrogate values retain a parser notice but System.Text.Json rejects them at runtime.
Enable JavaScript to generate code. You can still read and edit JSON.
This browser cannot start the local Worker. Generation is unavailable.
All elements and documents contribute to one contract. An array root stays an array. An absent field differs from null.
Up to 20 documents, 1,000,000 UTF-16 input units and 2,000,000 output units; other resource budgets also apply.
Your JSON is processed locally in a browser Worker. It is not uploaded or stored.
Changing to one document keeps only the active example. Confirm or cancel.
Use 1–64 ASCII letters and digits, beginning with a letter. Reserved names are rejected.
Ready for JSON input.
Some diagnostic details are omitted. Notice totals remain visible.
Name details
Clipboard is unavailable or denied. Download the file or explicitly open the complete code for manual copying. A large file may take longer to display.
Complete examples and root arrays
Paste strict JSON or choose a local UTF-8 file. Generate from one document or up to twenty complete examples. Every element and late field contributes; a root array stays an array. Empty inputs, decoded duplicate keys, comments, trailing commas and concatenated documents stop generation without losing your examples.
The editor shows the active example and total count. After generating, review the filename, root type expression, JSON node count and size of the complete code. These details describe the current result; copying and downloading include the full file even when the preview is shortened.
[{"id":1},{"id":2,"nombre":"Ana"}]
#nullable enable
namespace Generated;
public sealed class RootItem
{
[global::System.Text.Json.Serialization.JsonRequired]
[global::System.Text.Json.Serialization.JsonPropertyName("id")]
public long Id { get; set; }
[global::System.Text.Json.Serialization.JsonPropertyName("nombre")]
public string? Nombre { get; set; }
}
public static class Root
{
public static global::System.Collections.Generic.List<RootItem> Deserialize(string json)
=> global::System.Text.Json.JsonSerializer.Deserialize<global::System.Collections.Generic.List<RootItem>>(json)!;
}
Exact attributes, required presence and nullable capabilities
Every property has an exact JsonPropertyName attribute, even when the name matches its PascalCase member. Quotes, backslash, controls, emoji, NFC and NFD keys remain distinct. Code identifiers change for collisions, enclosing class names and inherited members such as Equals or GetType. Isolated surrogates in keys stop generation. Output uses public sealed classes in namespace Generated with public get/set properties and globally qualified standard-library types; no configurable namespace, records, packages or custom converters.
JsonRequired requires a JSON property to be present; an omitted required property causes JsonException. An optional property has no JsonRequired and uses T? or JsonElement? for raw. Absence and explicit null can both become null, including optional raw fields; a notice explains this collapse. Null-only required fields use JsonElement with ValueKind Null. Required nonnullable references initialize to default! to satisfy static analysis, which is not a valid data default. Nullable annotations in .NET 8 do not reject explicit null for required references; a global notice explains that capability. No global WhenWritingNull is enabled and no presence-preserving round-trip is promised.
Numbers and complete local exports
Pure integer lexemes fitting int64 and without negative zero use long, including 9007199254740993 and the int64 endpoints. Decimals, exponents, -0 and integers outside int64 use JsonElement with a raw-number notice; GetRawText preserves the original lexeme. Parser precision notices remain visible. Unknown, null-only and unions with multiple nonnull branches use JsonElement with notices; empty objects use Dictionary<string, JsonElement>. A nonempty object root is a direct class; every other root has a public static Deserialize(string json) helper, including lists, primitives and nullable/object unions. This helper delegates to System.Text.Json and does not validate the inferred contract. An isolated surrogate in a string value does not prevent generating a type, but the .NET 8 consumer rejects that value; the parser notice remains visible.
Limits: 20 samples, 1,000,000 UTF-16 input units, 4,000,000 UTF-8 bytes in total and per file, depth 200, 100,000 source nodes/inference visits, 1,000,000 parse work units, 10,000 types, 20,000 fields, 2,000,000 merge work units, 2,000 declarations, 4,000,000 emission work units and 15 seconds. Output allows 2,000,000 UTF-16 units and 8,000,000 bytes. These maxima cannot necessarily be reached together; exceeding a hard limit yields no partial code.
The preview contains at most 20,000 UTF-16 units; copy and download include the entire current Types.cs as text/plain;charset=utf-8, UTF-8 without BOM and LF with a final newline. At most 100 diagnostic details and 50 name rows totaling 10,000 units are shown with omitted counts. Denied clipboard access offers explicit manual copying of complete code. One initial BOM is removed only for parsing; positions use the original editor text. Cancel terminates the Worker; edits, mode, sample order and options invalidate the output. Processing stays in a local Worker, offline after assets load, without uploads, storage or data in related links. JavaScript and Worker support are required; generated C# is never compiled or executed in the browser.