JSON to C# Class

Convert JSON to C# classes or records with JSON attributes

A free JSON to C# converter: paste JSON and get POCO classes or records back instantly. Choose a plain class with get/set properties for mutable models, or a positional record for immutable value types. Property types are inferred from the data, nested objects become their own classes, and [JsonPropertyName] (System.Text.Json) or [JsonProperty] (Newtonsoft.Json) attributes preserve the original JSON key names. Conversion runs entirely in your browser, so your JSON is never uploaded to a server.

Options on this page

Output formats: Class (POCO with get/set auto-properties), Record (Immutable C# 9+ positional record).

OptionWhat it does
Root Class NameNames the top-level POCO.
Namespace (optional)Emitted as a file-scoped namespace (C# 10+) at the top of each file.
Field Naming ConventionOne of PascalCase, camelCase, Preserve Original. Defaults to PascalCase.
Type for null valuesEither object or string, used when a key is null in every sample.
Non-nullable value typesEmit int / long / double / bool instead of int? / long? / double? / bool? for fields present in every sample.
Separate ClassesWrite each class to its own .cs file. Off (the default) puts every class in one file, so Copy All pastes into a single file that compiles.
Add JSON attributesAnnotate properties with the original JSON key — [JsonPropertyName] or [JsonProperty], depending on the library. Without them a property only binds to a key spelled exactly like it (System.Text.Json is case-sensitive), so snake_case or camelCase keys are silently ignored.
Nullable reference typesEmit #nullable enable and mark string, object, List<T> and class properties as nullable (string?). Off emits #nullable disable.
JSON libraryOne of System.Text.Json or Newtonsoft.Json; picks which JSON library the generated code is written for.

How JSON values map to C# types

JSON valueC# type
stringstring
integerint (int?)
integer beyond 32 bitslong (long?)
decimaldouble (double?)
true / falsebool (bool?)
ISO-8601 timestampDateTime (DateTime?)
arrayList<T>
objectnested class
nullobject (configurable)

Example

Input JSON

{
  "id": 12345,
  "product_name": "Wireless Mouse",
  "price": 24.99,
  "in_stock": true,
  "tags": ["electronics", "accessories"],
  "manufacturer": {
    "name": "Acme Corp",
    "country": "US"
  }
}

Generated C#

public class Product
{
    [JsonPropertyName("id")]
    public int? Id { get; set; }

    [JsonPropertyName("product_name")]
    public string ProductName { get; set; }

    [JsonPropertyName("price")]
    public double? Price { get; set; }

    [JsonPropertyName("in_stock")]
    public bool? InStock { get; set; }

    [JsonPropertyName("tags")]
    public List<string> Tags { get; set; }

    [JsonPropertyName("manufacturer")]
    public Manufacturer Manufacturer { get; set; }
}

Frequently asked questions

How do I convert JSON to a C# class?

Paste your JSON into the input pane and the C# classes appear beside it immediately. Pick Class for a mutable POCO with get/set properties or Record for an immutable positional record, set the root class name and an optional namespace, then copy the code or download it. Nested JSON objects become their own classes and arrays become List<T>.

What is a POCO?

POCO stands for Plain Old CLR Object: an ordinary C# class with properties and no dependency on a framework base class. POCOs are what System.Text.Json and Newtonsoft.Json deserialize JSON into, so turning a JSON sample into a POCO is the usual first step when consuming a JSON API from C#.

Should I choose System.Text.Json or Newtonsoft.Json?

System.Text.Json ships with .NET and is the default for new projects; it emits [JsonPropertyName] from System.Text.Json.Serialization. Newtonsoft.Json is a separate NuGet package that many existing codebases still use; it emits [JsonProperty] from Newtonsoft.Json. The generated properties are identical apart from the attribute and its using.

Why are the value types int? and double? by default?

A JSON value can be null or missing, and a plain int would silently turn that into 0. The default keeps the nullable form so nothing is lost; turn on Non-nullable value types to get plain int, long, double, and bool for fields that are present in every sample.

Is my JSON uploaded anywhere?

No. Parsing, type inference, and code generation all run in your browser using JavaScript. Your JSON is never sent to a remote server, and there is no account to create. The page keeps your last input and settings in your own browser (localStorage) so they survive a reload; nothing is stored anywhere else.

Is it safe to paste confidential JSON, such as API responses or customer data?

The conversion itself never transmits your JSON, so a confidential payload does not leave your machine. You can verify this: open your browser DevTools, switch to the Network tab, and convert something — no request carries your data. Two things to know: your last input is saved in your browser's localStorage (clear site data to remove it), and the Copy Link button embeds your JSON in the link, so anyone who opens that link, and the server that receives the request, can see it. Only share such links where you are comfortable with that.

Does it cost anything?

No. The generator is free to use with no sign-up and no usage limits.

How are nested objects handled?

Each nested JSON object becomes its own named type, derived from the key it appeared under. Arrays of objects are widened across every element, so a field that is a whole number in one element and a fraction in another gets a type that holds both.

Other languages

More JSON tools