JSON to C#

Generate C# classes from JSON.

About the JSON to C#

Paste a JSON payload and get C# classes for it. Each object becomes a public partial class of auto-properties, a nested object gets its own class named after the key holding it, and whole numbers are typed long rather than int. The output is plain types with no serializer attributes, so it drops into a project using System.Text.Json or Newtonsoft.Json alike.

How to use the JSON to C#

  1. Paste your JSON into the input panel, or press Sample to load an example.
  2. Set Root name to whatever the top-level class should be called.
  3. Press Generate to produce the classes.
  4. Copy the result, or Download it as Types.cs.

Frequently asked questions

Why are whole numbers typed long instead of int?
A JSON number carries no declared width. long accepts everything int would plus larger values, so a payload whose sample happened to hold only small numbers cannot overflow later. Narrow it by hand if you know the real range.
Where are the [JsonProperty] attributes?
There are none — the output is plain classes. Property names are PascalCased from the JSON keys, so user_name becomes UserName. System.Text.Json matches property names case-sensitively by default, so set PropertyNamingPolicy or PropertyNameCaseInsensitive when you deserialize.
What namespace do the classes use?
QuickType, the generator's default. Rename it to your own namespace after pasting; nothing else in the output depends on it.
Are nested objects and arrays handled?
Yes. A nested object becomes its own class referenced as a property, and a JSON array becomes an array of the element type — a list of strings comes out as string[].
Is my JSON sent to a server?
No. Generation runs in your browser, which matters when the sample you are pasting is a real API response rather than a scrubbed one.

Related tools