Skip to content
gohacks.dev
Tooling

JSON to C# Class Generator

Generate C# classes or records from a JSON sample, with PascalCase properties, JsonPropertyName attributes and nullable types for missing values.

Free · No sign-up · Your inputs stay in your browser

Input

Generate C# types from JSON

Output

C#

1,093 characters

Written for System.Text.Json: each property carries [JsonPropertyName] with the original key, so PascalCase names still bind. Nullable value types (long?, bool?) mark keys that are null or missing in the sample; enable <Nullable> in the project for the reference types. Types come from this one sample: give fields that are null here a real value to type them.

Runs in this browser. Nothing you paste is sent to a server.

System.Text.Json conventions

The attributes target System.Text.Json, the serializer built into .NET. Because every property names its JSON key explicitly, the output works whatever JsonSerializerOptions.PropertyNamingPolicy is set to. Newtonsoft.Json users can swap the attribute for [JsonProperty("...")].

Nullable reference types

Value types such as long and bool are marked with ? when the sample shows them null or missing. Reference types such as string and List are only checked by the compiler when <Nullable>enable</Nullable> is on in the project, which is the default in new .NET templates.

Share

Frequently asked questions

Should I generate records or classes?
Records give value equality and immutability with init-only properties, which suits DTOs. Use classes when a framework needs to set properties after construction or when the objects are mutated.
Does Visual Studio have this built in?
Yes: Edit, Paste Special, Paste JSON as Classes. It does not add JsonPropertyName attributes or nullability from the sample, which is what this generator adds.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools