JSON to C#
Paste a JSON sample and get C# classes, instantly and entirely in your browser. Optional fields, nullability and nested types are inferred from the sample — and anything the sample cannot settle is reported rather than guessed.
Type definitions will appear here
C# classes from a sample
Generates classes with [JsonPropertyName] attributes and nullable value types where the sample allows null.
Large integers become long rather than int.
What a sample cannot tell you
Types are inferred from one sample. A field absent from your sample will be absent from the output, and a field that happens to hold only whole numbers will be typed as an integer even if it can hold decimals. Paste the widest sample you have. For a guarantee rather than an inference, start from a JSON Schema.
What C# output looks like
Generated from two sample records, one of which has an extra field and a null. This is the actual output, not an illustration:
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Root
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("userName")]
public string UserName { get; set; }
[JsonPropertyName("isActive")]
public bool IsActive { get; set; }
[JsonPropertyName("score")]
public double Score { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; }
[JsonPropertyName("address")]
public Address Address { get; set; }
[JsonPropertyName("lastSeen")]
public string LastSeen { get; set; }
[JsonPropertyName("nickname")]
public string Nickname { get; set; }
}
public class Address
{
[JsonPropertyName("city")]
public string City { get; set; }
[JsonPropertyName("postcode")]
public object Postcode { get; set; }
}
The three things that differ by language
Large integers
Large integers become long rather than int. System.Text.Json will throw on overflow rather than wrapping, so the wrong type surfaces immediately.
Optional against nullable
Nullable value types are used where a sample allowed null, so int? is distinguishable from a defaulted 0.
Names that are not identifiers
[JsonPropertyName] is emitted so PascalCase properties map to the original keys without a global naming policy.