JSON tools

JSON to C# Class and Record Generator

Paste JSON and get C# records or classes ready for System.Text.Json or Newtonsoft.Json, with PascalCase properties mapped to the original keys.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.

C# options

Every option has a tooltip. Your choices are remembered on this device; your JSON never is.
Reset options to defaults
Name of the top-level type. If your JSON is an array, this names each item. Nested types are named after their keys.
Positional records (C# 9+): immutable, concise, value equality. Ideal for DTOs.Mutable classes with { get; set; } properties, for older code or ORMs.
Which attributes map JSON keys to PascalCase properties. None writes plain types; set a naming policy yourself.
File-scoped namespace (C# 10+). Leave empty for none.
The everyday choice; works with every serializer.Plain arrays: fixed size, slightly faster.Read-only view, signals the data shouldn't be modified.
Annotate reference types with ? where the sample had null or a missing key (#nullable enable).
Classes only: the C# 11 required modifier on properties every sample had. System.Text.Json (.NET 7+) then rejects JSON that omits them.
Type ISO 8601 date-times as DateTimeOffset, which keeps the UTC offset (DateTime would lose it).
Type strings that were UUIDs in every sample as Guid.

JSON sample

Paste a real response. Arrays are treated as samples: keys missing from some items become optional, null values nullable.
Clear

C# models

CopyDownload Models.cs
Paste JSON or load the example. Code is generated in your browser as you type.

Need this built into your own API or pipeline? Talk to our team

Quick answer

To deserialize JSON in C#, you need a record or class whose properties match the JSON keys. Paste a sample into Playxoft's free JSON to C# generator to get them: keys become PascalCase properties with JsonPropertyName attributes, whole numbers become int or long, dates become DateTimeOffset, and values that are null or missing become nullable. Then call JsonSerializer.Deserialize with your root type.

  • Records or classes
  • System.Text.Json or Newtonsoft
  • JsonPropertyName attributes
  • Nullable reference types
  • C# 11 required members
  • DateTimeOffset and Guid
  • File-scoped namespace
  • Download Models.cs

How to use the JSON to C#

  1. 1Paste JSON into JSON sample and set the Root type name.
  2. 2Choose Records or Classes, and a Serializer: System.Text.Json, Newtonsoft.Json or none.
  3. 3Enter a Namespace, pick a Collection type, and toggle Nullable references, required members, DateTimeOffset and Guid.
  4. 4Copy the code or download Models.cs into your project.
  5. 5Deserialize with JsonSerializer.Deserialize<Root>(json), or JsonConvert.DeserializeObject<Root>(json) for Newtonsoft.

System.Text.Json or Newtonsoft.Json?

Both turn JSON into C# objects, and the generator writes the right attributes for either.

System.Text.JsonNewtonsoft.Json (Json.NET)
Ships with.NET Core 3.0 and laterA NuGet package
Key attribute[JsonPropertyName("key")][JsonProperty("key")]
Property name matchingCase-sensitive by defaultCase-insensitive
Single quotes, unquoted keysRejectedAccepted
Native AOT and trimmingYes, with source generationNo

For new code, System.Text.Json is the default: it is built in, fast and actively developed. Keep Newtonsoft.Json where a codebase already depends on its flexibility, such as custom converters, JObject manipulation or loosely formatted input.

Records or classes for JSON models?

Records (C# 9 and later) are the modern choice for data transfer objects: one line per property, immutable, and compared by value, which makes them ideal for API payloads you read but don't mutate. System.Text.Json fills positional records through their constructor:

public record User(
    [property: JsonPropertyName("id")] long Id,
    [property: JsonPropertyName("email")] string? Email
);

The property: target matters. Without it the attribute lands on the constructor parameter: System.Text.Json's [JsonPropertyName] isn't allowed there, so the code won't compile (CS0592), and Newtonsoft's [JsonProperty] would rename the key when reading but not when writing.

Classes with { get; set; } properties suit code that builds or edits objects field by field, older frameworks, and ORMs that need a parameterless constructor. Switch the generator to Classes and turn on required members to make missing keys fail loudly.

How are JSON types mapped to C#?

JSON in your sampleC# type
Whole numbers that fit 32 bitsint
Larger whole numberslong
Whole numbers beyond longdecimal
Decimal numbersdouble
ISO 8601 date-time stringsDateTimeOffset
UUID stringsGuid
Other stringsstring
ArraysList<T>, T[] or IReadOnlyList<T>
ObjectsA record or class named after the key
Empty or ID-keyed objectsDictionary<string, T>
Mixed types, or only nullJsonElement (object with Newtonsoft)

Switch double to decimal for money: double can't represent 0.1 exactly, while System.Text.Json reads a JSON number straight into decimal without that rounding. DateTimeOffset is preferred over DateTime because it keeps the UTC offset that ISO 8601 timestamps carry.

Do I need [JsonPropertyName] on every property?

Not if the API's naming is consistent. Set a naming policy once and drop the attributes:

var options = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, // .NET 8+: user_id maps to UserId
};
var user = JsonSerializer.Deserialize<User>(json, options);

// Or the web defaults: camelCase names, case-insensitive matching
var web = new JsonSerializerOptions(JsonSerializerDefaults.Web);

The generator writes explicit attributes anyway, because real APIs are rarely consistent: a userId, a created_at and a 2fa often share one payload. Attributes make every mapping visible and survive renaming a property in your IDE. Choose Serializer: None (plain) if you prefer bare types plus a policy.

Visual Studio's Edit > Paste Special > Paste JSON As Classes is a quick start, but its property names follow the keys as written and it adds no attributes, nullable annotations or records. This generator writes idiomatic PascalCase properties, maps each one back to its original key, and lets you choose records or classes.

How do nullable reference types and required work with JSON?

With #nullable enable, a string property promises never to be null. The generator marks a property nullable (string?, int?) whenever a sample had null or left the key out, so the compiler warns before you dereference it.

On classes, required members (C# 11) go further: System.Text.Json in .NET 7 and later throws a JsonException when a required property is missing from the input, turning a silent null into an early, clear error. For trimmed or Native AOT apps, add a source-generated context so no reflection is needed at runtime:

[JsonSerializable(typeof(User))]
internal partial class AppJsonContext : JsonSerializerContext { }

var user = JsonSerializer.Deserialize(json, AppJsonContext.Default.User);

Frequently asked questions

Usually the JSON keys don't match the property names. System.Text.Json is case-sensitive by default, so userId won't fill UserId without an attribute or naming policy. The generated JsonPropertyName attributes map every key explicitly.
Use decimal for money. A double can't represent many decimal fractions exactly, so sums drift by tiny amounts. Change the generated double to decimal for currency fields; System.Text.Json and Newtonsoft.Json both deserialize JSON numbers into decimal.
ISO 8601 timestamps carry a UTC offset, such as Z or +02:00. DateTimeOffset keeps that offset, while DateTime can silently convert to local time or lose it. Turn off DateTimeOffset to get plain strings instead.
Yes. Choose Newtonsoft.Json as the serializer and the generator writes JsonProperty attributes with the property target. Json.NET fills positional records through their constructor.
Yes. Choose Classes and Newtonsoft.Json, and turn off required members, since records and required need newer C# versions. Turn off Nullable references if your project doesn't use them.
Paste JSON As Classes, under Edit and Paste Special, creates plain classes whose property names copy the JSON keys, with no serializer attributes, nullable annotations or records. This generator writes PascalCase properties mapped to the original keys, marks nullable and required members, and can emit records for System.Text.Json or Newtonsoft.Json.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Fighting messy data every day?

When payloads, schemas and integrations keep breaking, the fix is usually upstream. We design typed APIs and backends that stay clean as you grow. Tell us what you are building and we will suggest the simplest architecture that fits.