UTILS.
100% in-browser
💠

JSON to C# Classes

Generate C# model classes from a JSON sample for System.Text.Json or Newtonsoft.Json, with PascalCase properties and nullable value types.

output

About this tool

The JSON to C# Classes tool converts a pasted JSON sample into C# model classes or records, so .NET developers can scaffold DTOs from an API response in seconds. It parses the JSON, infers C# types recursively, and emits one type per object: strings become string, ISO date-time strings DateTime, integers int or long, other numbers double, booleans bool, arrays List<T>, and nested objects their own PascalCase classes declared before the parents that reference them.

All parsing and code generation happen locally in your browser with JSON.parse and plain JavaScript — nothing is uploaded. Properties are emitted as PascalCase auto-properties, public T Prop { get; set; }. When the JSON key differs from the PascalCase property name the tool adds [JsonPropertyName("originalKey")] for System.Text.Json or [JsonProperty("originalKey")] for Newtonsoft, and only the required using directives are included.

Value-type properties that can be null in any sample are made nullable (int?, double?, bool?, DateTime?), while reference types like string and List are already nullable. The serializer toggle switches attribute and using style between System.Text.Json (default) and Newtonsoft.Json; the shape toggle emits either classes (default) or records. Copy the code or download it as a .cs file.

Frequently asked questions

How are JSON types mapped to C#?
string to string, an ISO date-time to DateTime, integer to int (long beyond the int range), non-integer number to double, boolean to bool, array to List<T>, and object to a named class or record. Nullable value types get the trailing ? modifier.
System.Text.Json or Newtonsoft?
The serializer toggle picks either. It controls the attribute used when a property name differs from the JSON key — [JsonPropertyName("key")] for System.Text.Json or [JsonProperty("key")] for Newtonsoft — and the corresponding using directive.
Can I generate records instead of classes?
Yes. The shape toggle switches between public class (default) and public record, keeping the same PascalCase auto-properties and JSON attributes so you can choose the style your codebase prefers.
Is the JSON processed privately?
Yes. Everything runs in your browser with JSON.parse and plain JavaScript; the sample is never uploaded, so pasting real API payloads is safe.

More tools