๐Ÿงฉ

JSON to C# Class Generator

Generate C# classes from JSON with nested types and optional JsonPropertyName attributes. Edit with syntax highlighting and download a .cs file.

Practical Guide
Settings
Class Name
Name for the generated root C# class
Add JsonPropertyName attributes
Annotate properties with JsonPropertyName("key") to keep original JSON casing
Enable nullable references
Append ? to reference/value types when the JSON value can be null
Generate partial classes
Mark every class as partial so you can extend it in separate files

Input JSON

Valid JSON

โ“What is this?

The generator infers a C# model from sample values. Objects become classes and arrays are represented as lists. A sample helps start a model for an API response or configuration file.

โœจFeatures

โšก

Distinct C# property names

Keys that normalize to the same C# name get distinct identifiers. With JsonPropertyName enabled, each attribute preserves its exact JSON key.

๐ŸŽฏUse Cases

Model an API response

Paste a representative JSON response, inspect its nested classes and export the C# source to use in a .NET project.

๐Ÿ“šPractical Guide

Types inferred from values

Objects become classes, integers become long and decimals become double. Same-type arrays become List<T>, while mixed arrays fall back to List<object>.

๐Ÿ’ฌFrequently Asked Questions

โ“What happens to a top-level array?
A top-level array is wrapped in an Items property, and a primitive is wrapped in Value. For a bare JSON array, deserialize the list type directly.
๐Ÿ’ฌHow is nullability inferred?
The nullable option adds a question mark when the sample contains null. Fields absent from the sample and the full API schema need to be checked separately.

๐Ÿ’กPractical Guide

๐Ÿ’ก

Load Sample

Load the sample, then convert it. Compare the generated names for display-name and display_name, and check how the quoted JSON key is written in JsonPropertyName.

๐Ÿ”—Related Documents

๐Ÿ“–Microsoft Learn ยท JsonPropertyNamePreserve JSON property names when using C# naming conventions.

๐Ÿ“Update Log

๐Ÿ“Œv1.1.261128
v1.1.261128

Fixed collisions in class and property names and escaping of JSON keys. Added JSON and C# syntax highlighting and a sample that exercises these cases.

v1.0.251115

Initial release with JsonPropertyName toggle, nullable reference handling, summary panel, and download-ready .cs export

๐Ÿ“ฆRecommended Components

User Comments

0 / 2000
Loading...