{ }jsonkit
Format
Validate
Convert
Query
Generate
→C#

JSON to C# Class & 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 representative JSON document into typed C# models you can use with an API client, ASP.NET endpoint, background job or test fixture. It follows nested objects into separate named types, converts arrays to generic lists and distinguishes integer, floating-point, Boolean, string and nullable values.

Choose concise C# records for immutable data-transfer models or sealed classes with required init-only properties. The System.Text.Json option adds JsonPropertyName attributes, which preserve keys such as order_id or created-at even when the generated property uses a valid PascalCase C# identifier.

Generation happens entirely inside your browser. Customer records, access tokens and unpublished API examples are never uploaded. The output is a practical starting point rather than a claim about every payload your API might return, so compare it with the API contract before shipping it.

How it works

Infer C# types from JSON values

Whole numbers become long, decimal values become double, booleans become bool and text becomes string. Arrays become List<T>. A null value makes the inferred member nullable, while incompatible mixed values fall back to object so the generated model does not pretend the sample proved a narrower type.

Merge object shapes inside arrays

When an array contains several objects, the generator examines every element rather than only the first. Shared keys keep one property type and keys missing from some elements become nullable. Nested object and array models are emitted with readable singular names.

Records or required-property classes

Record mode emits sealed positional records that work well for data-transfer objects and value-style models. Class mode emits sealed classes with init accessors and uses the C# required modifier for members that were present and non-null throughout the sample.

System.Text.Json property names

Enable JSON attributes to add System.Text.Json.Serialization imports and JsonPropertyName annotations. This makes renamed or sanitized members deserialize from their exact original JSON keys without requiring a global naming policy.

Frequently asked questions

Does the generated C# compile without another package?

The model types use the .NET standard library. JsonPropertyName comes from System.Text.Json, which is included with modern .NET. Records and required properties need a suitably recent C# language version; switch to classes or adjust the output for older projects.

How are missing and null properties represented?

A key missing from some sampled array objects, or a key whose value is null, receives a nullable type. With only one object sample, the tool cannot know that a currently present property is optional in other responses.

Why did a field become object?

Object is the safe fallback for empty arrays, null-only values or fields whose sampled values have incompatible structures. Add more representative non-null elements or replace object manually using knowledge from your API schema.

Is JSON data sent to a server?

No. JSON parsing, shape inference and C# rendering all run locally in the browser tab. Nothing you paste is uploaded by this tool.