Developer Tools

JSON to C# Class

Paste JSON and get C# model classes ready for System.Text.Json or Newtonsoft.Json. Properties use PascalCase with attributes that map them to the original JSON keys, numbers become int, long or double depending on their values, ISO dates can become DateTimeOffset, and optional or null fields become nullable. Choose classes or records, List<T> or arrays, and set your namespace.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use JSON to C# Class

  1. Paste a JSON sample.
  2. Choose class or record and your serializer.
  3. Set the root class name and namespace.
  4. Copy the code or download Models.cs.

JSON to C# Class features

Two serializers

[JsonPropertyName] for System.Text.Json or [JsonProperty] for Newtonsoft.

Right number types

int or long by value range, double for decimals.

Nullable aware

int?, bool? and string? where the sample shows missing or null values.

Classes or records

get; set; for classes, get; init; for records.

Dates

Optional DateTimeOffset for ISO 8601 strings.

Ready to compile

Usings, namespace and initialisers for non-nullable references.

When to use JSON to C# Class

  • Creating DTOs for an ASP.NET Core API client.
  • Deserializing a third-party webhook in an Azure Function.
  • Modelling a JSON configuration file for a .NET app.
  • Replacing Visual Studio’s Paste JSON as Classes outside the IDE.

JSON to C# Class FAQ

Why are there attributes on every property?

They map PascalCase property names to the exact JSON keys, so deserialization works whatever the JSON naming style and even for keys like "is-active".

When is long used instead of int?

When a sample value does not fit in a 32-bit int. Review IDs: if they can grow beyond 2,147,483,647, use long even if the sample is small.

What does “Nullable reference types” change?

It adds #nullable enable, marks optional strings and objects with ?, and initialises required ones so the compiler does not warn.

What about fields with mixed or unknown types?

They become JsonElement (System.Text.Json) or JToken (Newtonsoft), which can hold any JSON value.

Should I use records?

Records with init-only properties suit immutable DTOs. Classes with setters suit models you modify after loading.

Is my JSON uploaded?

No. The code is generated in your browser.

Mapping JSON to C# types

C# is statically typed, so reading JSON into objects requires classes whose properties match the JSON structure. Writing them by hand for a large payload is tedious, and small mistakes, such as a typo in a property name or an int for a value that can be a decimal, only show up at run time as missing data. Generating the classes from a real sample avoids both problems.

Every JSON object becomes a class named after its key, with one property per field. Property names follow .NET conventions in PascalCase, and each carries a JsonPropertyName or JsonProperty attribute with the original key, so the mapping is explicit and unaffected by serializer naming policies. Arrays become List<T> or T[], and objects that appear with the same structure in several places share a class.

Number types are chosen from the values in the sample. Whole numbers that fit in 32 bits become int and larger ones long, while numbers with decimals become double; if money is involved, consider changing double to decimal. With date detection on, strings in ISO 8601 format become DateTimeOffset, which preserves the time zone offset and is the safest type for timestamps.

Nullability is inferred from the sample too. A value type such as int or bool becomes int? or bool? when the field is missing or null in some objects, and with nullable reference types enabled, strings and nested objects get ? in the same situations. Required reference properties receive an initial value so the compiler does not report possible null warnings.

Check the generated models against the API’s documentation before shipping. A sample cannot reveal optional fields that happened to be present, enum-like strings with a fixed set of values, or number fields that can exceed the range seen. Those refinements are quick to make once the structure is in place.

Other useful tools