JSON to C# Class

Paste JSON and get C# classes with properties ready for System.Text.Json.

Add JSON and click Generate to see the code here.

How JSON to C# Class works

Generates C# classes from a JSON sample. Each JSON object becomes a class with properties, and nested objects get their own class named after their key. The code works with System.Text.Json.

For an array of objects, all items are merged into one class, so keys that only some items have are included too. Type the class name you want in the Name box. Default is RootObject.

Input to JSON to C# Class

  • Paste or type JSON into the input box, or upload a .json or .txt file. Then click Generate.
  • Use real sample data. Types are read from the values, so 42 gives long, 4.2 gives double and "text" gives string.
  • Input must be valid JSON. If something is wrong, you see the line and column of the first error.

Output from JSON to C# Class

  • C# code with the using lines it needs, then one public class for each object shape.
  • Property names are PascalCase. Each one has a [JsonPropertyName] attribute with the original JSON key.
  • Values that can be null or missing get a ? like long?. Arrays become List, and strings and lists start with a value so they are never null.
  • Copy it, download it as Models.cs or open it in full screen.