jsontoolskit.org
JSON and JSON Schema utilities, in the browser
Say hi →

JSON to C#

JSON sample → classes or records · updated 28 July 2026

Generate C# types from a JSON sample. Properties are PascalCased with a [JsonPropertyName] attribute preserving the original key, and optional fields get nullable annotations so the compiler helps you handle missing data.

Paste input to start.

How to generate C# classes from JSON

  1. Paste a JSON sample — ideally an array of several records, so optional fields are detected.
  2. Set the Root type name. Nested objects are named after the key that holds them, singularised for arrays.
  3. Choose class for mutable models with get; set;, or record for a concise immutable positional type.
  4. Set a Namespace to get a file-scoped namespace X; declaration.
  5. Copy the code, or download it as a file.

Type mapping

Getting good types out of a sample

Type inference from a sample is only as good as the sample. Three habits make the output far more useful:

Privacy

Nothing is uploaded. Inference and code generation run in this tab. No server sees the payload you paste — which matters, because real API responses tend to contain real user data.

FAQ

Does System.Text.Json need the attributes?

Only when names differ. Its default matching is case-insensitive for property names, so userName often binds to UserName without help — but user_name does not. Keeping the attributes makes the mapping explicit and survives a rename.

Can I use these with Newtonsoft.Json instead?

Yes, but swap [JsonPropertyName("x")] for [JsonProperty("x")] and the using directive for Newtonsoft.Json. The type shapes are identical.

Why long instead of int?

Because a sample cannot prove a value fits in 32 bits, and silently overflowing on a large ID is worse than an over-wide column. Narrow it once you know the range.