JSON to C# Class Generator

Generate C# classes with auto-properties and System.Text.Json attributes from a JSON sample.

JSON
C#
Runs locally in your browser

About the JSON to C# Class Generator

This is the "Paste JSON as Classes" feature of Visual Studio, without Visual Studio. Every object shape in the sample becomes a class with public auto-properties named in PascalCase, and each property carries a [JsonPropertyName] attribute holding the original JSON key so deserialisation works even when the key is camelCase or snake_case.

Type mapping follows the usual conventions: int, double, string, bool, List<T> for arrays and object for nulls. The using directives for System.Collections.Generic and System.Text.Json.Serialization are included. If you use Newtonsoft.Json instead, replace the attribute with [JsonProperty] with a find-and-replace.

Nullable reference types, records and init setters are deliberately not emitted, since they depend on the language version and project settings; the output compiles on every C# version from 7 up and is easy to modernise.

How to use

  1. Paste a JSON sample on the left and set the root class name.
  2. Copy the classes into a new .cs file.
  3. Deserialise with JsonSerializer.Deserialize<Root>(json).

Common questions

Does this work with Newtonsoft.Json?
Yes, after replacing [JsonPropertyName("x")] with [JsonProperty("x")] and the using directive with Newtonsoft.Json.
Why are numbers int or double and not decimal?
JSON does not distinguish, so the generator picks int for whole numbers and double for decimals. Change to decimal for currency fields.
How are null values typed?
As object, because a single null gives no information about the real type. Replace with the correct type once you know it.