JSON to C# classes

Paste JSON and get C# classes with System.Text.Json attributes and nullable value types. Runs in your browser; nothing is uploaded.

About this converter

Visual Studio has had Paste Special as JSON Classes for years, which is fine until you are not in Visual Studio - on a Mac, in Rider, in VS Code, or looking at a response in a browser tab on a machine that is not yours. This does the same job from any browser.

Output uses System.Text.Json attributes rather than Newtonsoft, since that has been the default serialiser since .NET Core 3.0 and it is what a new project will have available without a package reference. A JSON key that differs from the C# property name gets a JsonPropertyName attribute preserving the original; keys that already match the PascalCase convention get no attribute, which keeps the output clean instead of uniformly annotated.

Properties are auto-properties with public getters and setters, which is what serialisers need and what most consuming code expects.

Nullability is handled carefully, and it is the part worth checking. Value types - long, double, bool - get an explicit question mark when the field was missing from some records, because a non-nullable value type cannot represent absence and would silently become zero or false. Reference types like string and List are left as they are, since they are already nullable, and marking them would just produce noise under nullable reference types.

Whole numbers become long rather than int, because JSON numbers coming from JavaScript or Python services routinely exceed 32 bits. Narrow them yourself once you know the real range.

Nested objects become their own classes named after the containing key, singularised where plural. Arrays of objects are merged across all elements rather than sampled from the first, so a field present on only some records shows up as nullable instead of being missed entirely.

Types come from the sample you paste, not a schema, so review before relying on it. Everything runs in your browser.

Frequently asked questions

System.Text.Json or Newtonsoft?
System.Text.Json, the default since .NET Core 3.0. For Newtonsoft, replace JsonPropertyName with JsonProperty and change the using directive.
Why do only some properties have attributes?
An attribute is emitted only when the JSON key differs from the C# property name. Keys already in PascalCase need none.
Why are some value types nullable?
Because that field was missing from at least one record. Without the question mark a missing number would deserialise to 0, indistinguishable from a real zero.

Related converters