JSON to C# Class Generator

Generate C# classes with Newtonsoft.Json attributes from JSON. Handles nested classes, collections and null fields. Runs entirely in your browser.

Input JSON

How it works

Type mapping rules

JSON valueC# type
42int
3.14double
"hello"string
true / falsebool
nullobject
[1, 2, 3]List<int>
[{...}, {...}]List<Type>
{"a": 1}class

About JSON to C# Class

Deserializing JSON in .NET usually means writing POCO classes first, and hand-typing them for a large API response wastes time and invites typos. This tool generates plain C# classes from a JSON sample, complete with [JsonProperty] attributes so property names map back to the original keys — handy when the JSON uses snake_case, kebab-case, or abbreviations that differ from idiomatic C# property names. Nested objects become nested classes and arrays become List<T>.

The output mirrors only what the sample shows: fields missing from the sample are absent from the class, and fields that appear as null become object. After generating, review the result and make value types nullable (int?) where a field can legitimately be absent, or switch to System.Text.Json by replacing the attributes with [JsonPropertyName]. Everything runs on your device, so private payloads stay private.

How types are chosen

Every value maps through a short chain: `null` becomes `object`, and the numeric branch tests `Number.isInteger` to pick `int` or `double`. Because that test runs after JSON parsing, a large identifier written as `9007199254740993` has already lost precision before the type decision is made — and `int` is 32-bit in .NET, so it cannot hold the value even if the digits survived. Anything beyond 2^31 needs `long`.

Arrays become `List<T>`. An empty array yields `List<object>` because there is nothing to infer from, an array of objects produces a `List<FieldNameItem>` over a synthesised class, and a mixed array degrades to `List<object>`. Nested objects each become their own class, with array element classes named after the field plus an `Item` suffix.

Naming, attributes and layout

Member names come from a pascal-casing helper that replaces every non-alphanumeric run with a split and uppercases each part. It does not understand C# conventions, so `HTTP-header` becomes `HttpHeader` rather than `HttpHeader` with the acronym preserved, and a JSON key named `class` produces a member that will not compile until you rename it — the generator does not consult the keyword list.

Because that transformation mangles the key, correctness rests on the `[JsonProperty("...")]` attribute written above every member with the original key verbatim. That attribute is what makes deserialisation land on the right property no matter what the C#-side name became, and it is the one line you must keep if you rename anything.

What to fix before compiling

Two mappings need attention. A `null` field becomes `object`, which forces a cast on every read; for value types the fix is a nullable annotation such as `int?`, and for a genuinely polymorphic field it is `JsonElement` or a custom converter. And because every whole number becomes `int`, any 64-bit identifier needs `long` instead — a mismatch that surfaces at runtime as an overflow rather than at compile time.

The attributes target Newtonsoft.Json. On `System.Text.Json` the equivalent is `[JsonPropertyName]`, so either add that package or swap the attribute; the member names themselves are already correct either way. Nested classes are emitted ahead of their referents and `Root` last, so the file reads top-down, and every property is a public auto-property — which suits deserialisation but leaves nowhere to put validation until you add a backing field yourself.

For a payload that does not match the model exactly, this generator has no way to express the shape the Go or TypeScript tools can: there is no union type, no dictionary escape hatch for arbitrary keys, and no partial-class hook, so a field that is sometimes a string and sometimes an object has to become `object` and be cast at every call site.

Frequently Asked Questions

How do I convert JSON to C# classes?
Paste your JSON into the input and click Generate. The tool outputs C# POCO (plain old CLR object) classes with Newtonsoft.Json attributes, compatible with System.Text.Json and JsonSerializer.
Can I generate records instead of classes?
Yes. Toggle between class and record output. Records are useful for immutable data models in C# 9+. Both formats include the necessary using statements and namespace.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close