{ }jsonkit
Format
Validate
Convert
Query
Generate

JSON to C# class and record generator

Create nullable C# models with nested types and JSON attributes.
Style
353 B · paste or drop a file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
✓ complete353 B → 944 B0.0 ms

About JSON to C#

The JSON to C# generator turns a sample JSON document into typed C# models for an API client, ASP.NET endpoint, background job or test fixture. Nested objects become separate named types and arrays become generic lists. It tells apart integer, floating-point, Boolean, string and nullable values.

Choose C# records for immutable DTOs, or sealed classes with required init-only properties. The System.Text.Json option adds JsonPropertyName attributes. Keys such as order_id or created-at then map correctly even though the C# property uses a PascalCase name.

Runs in your browser. Nothing is uploaded. The output is a starting point based on one sample, not on every payload your API can return. Compare it with the API contract before you ship it.

How it works

Infer C# types from JSON values

Whole numbers become long, decimals become double, booleans become bool and text becomes string. Arrays become List<T>. A null value makes the member nullable. Mixed values that do not fit one type fall back to object, so the model does not claim a narrower type than the sample shows.

Merge object shapes inside arrays

When an array holds several objects, the generator reads every element, not just the first. Shared keys get one property type. Keys missing from some elements become nullable. Nested models get readable singular names.

Records or required-property classes

Record mode writes sealed positional records, a good fit for DTOs and value-style models. Class mode writes sealed classes with init accessors. It marks a member required when it was present and non-null across the whole sample.

System.Text.Json property names

Turn on JSON attributes to add the System.Text.Json.Serialization import and JsonPropertyName annotations. Renamed members then deserialize from their exact original keys without a global naming policy.

Frequently asked questions

Does the generated C# compile without another package?

The models use only the .NET standard library. JsonPropertyName comes from System.Text.Json, which ships with modern .NET. Records and required properties need a recent C# language version. For older projects, switch to classes or adjust the output.

How are missing and null properties represented?

A key missing from some objects in a sampled array, or a key whose value is null, gets a nullable type. With a single object, the tool cannot tell that a present property is optional in other responses.

Why did a field become object?

object is the safe fallback for empty arrays, null-only values and fields whose sampled values do not share a structure. Add more non-null examples, or replace object by hand using your API schema.

Is JSON data sent to a server?

No. Parsing, type inference and C# output all run in your browser tab.

Sources & last verified

We checked this tool's behavior and the claims on this page against the specifications below on . The tool runs in your browser, so the output you see is exactly what the engine produced.

Found a wrong result or an outdated claim? Report an error and we will check it again.