Skip to content

Menu

JSON to C#

Convert JSON to C# classes

Runs entirely in your browserConvertersFree, no sign-up
Loading tool

01What is JSON to C#?

Writing DTOs by hand for a large API response is slow and easy to get wrong. This generator reads a JSON sample and writes C# classes that mirror its shape, ready to paste into a .NET project. Types come straight from the values. Strings map to string, booleans to bool and decimals to double. Whole numbers map to int, or to long when a value doesn't fit in a 32-bit int. A null has nothing to infer from, so it becomes object. One quirk comes from JavaScript itself. JSON.parse reads 1.0 as the number 1, so a field sampled as 1.0 becomes int. Arrays get special care. Every element is merged into one sample before typing. An array of objects therefore produces a single item class holding every key seen in any element. A number list with one decimal becomes List<double>. Empty arrays, and arrays that mix JSON types, become List<object>. Each nested object gets its own class, named after its key in PascalCase. snake_case, camelCase, kebab-case and spaced keys are all converted. When a class name is already taken, a numeric suffix is added. Property names follow the same PascalCase rule, and they are cleaned to be legal C# identifiers. Invalid characters become underscores, and a name starting with a digit gets a leading underscore. C# also forbids a member with the same name as its class (compiler error CS0542), so that property gets a suffix too. Here is a small worked example. Feed it {"2fa":true,"class":"a","Root":1} with the root named Root. You get bool _2fa, string Class and int Root2. The digit was prefixed, class is safe once capitalised, and Root was renamed to avoid the clash. You pick between two styles. Auto Properties writes compact { get; set; } members. Full Properties writes private _camelCase backing fields, followed by properties with explicit get and set bodies. Either way, each nested class is generated once. A top-level array produces the item class plus a comment such as // Root type: List<Root>. A primitive root just produces a comment with its type. The output always opens with using System and using System.Collections.Generic. The limits are honest ones. The generator adds no [JsonPropertyName] attributes, so snake_case JSON needs a naming policy or attributes from you. It adds no nullable annotations either. It sees only your sample, so a field missing from the sample is missing from the class. Dates stay string, because JSON has no date type.

.NET, Unity and Azure Functions developers who need typed C# models for a JSON payload they have just received. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON to C#

  1. Paste a representative JSON sample into JSON Input
  2. Type a name into the Root class box (it defaults to Root)
  3. Choose Auto Properties or Full Properties
  4. Review the generated classes in C# Output
  5. Click Copy and paste the code into your project, then adjust types where needed

03Worked examples

Input: {"user_id":7,"full-name":"Ann","address":{"zip_code":"0150"},"meta":null} (Auto Properties)
Result: public class Root { public int UserId { get; set; } public string FullName { get; set; } public Address Address { get; set; } public object Meta { get; set; } } public class Address { public string ZipCode { get; set; } }
snake_case and kebab-case keys become PascalCase properties, and null becomes object because there is no type to infer. The using lines are left out here.
Input: {"ratio":1.0,"ints":[1,2.5]} (Auto Properties)
Result: public int Ratio { get; set; } public List<double> Ints { get; set; }
JSON.parse reads 1.0 as the number 1, so it becomes int; one decimal in an array is enough to make the list double.
Input: {"big":9007199254740993,"mixed":[1,"a"]} (Auto Properties)
Result: public long Big { get; set; } public List<object> Mixed { get; set; }
Integers beyond int range become long, and an array mixing numbers and strings becomes List<object>.
Input: {"id":1} (Full Properties)
Result: public class Root { private int _id; public int Id { get { return _id; } set { _id = value; } } }
Full Properties writes a private backing field for each property.
Input: [{"id":1},{"id":2,"tag":"x"}] (Auto Properties)
Result: public class Root { public int Id { get; set; } public string Tag { get; set; } } // Root type: List<Root>
A top-level array yields one item class with keys from every element, plus a comment naming the root type. The using lines are left out here.
Input: {"2fa":true,"class":"a","Root":1} (Auto Properties)
Result: public bool _2fa { get; set; } public string Class { get; set; } public int Root2 { get; set; }
A leading digit gets an underscore, and a property that would share the class name Root becomes Root2. Property lines only.

04Common use cases

  • Creating DTOs for a REST response you deserialize with System.Text.Json in an ASP.NET Core controller or HttpClient call
  • Modelling an appsettings.json section so you can bind it with the options pattern
  • Typing a webhook payload from Stripe, GitHub or a partner API inside an Azure Function
  • Giving a Unity or MAUI project typed models for a third-party JSON feed
  • Scaffolding classes for an integration test fixture you load from a .json file
  • Getting a first draft of models for a large legacy payload before trimming them by hand

05Tips

  • Add [JsonPropertyName("original_key")] or set JsonNamingPolicy.SnakeCaseLower, since PascalCase names won't match snake_case JSON on their own.
  • Paste several array elements, not just one. Keys that only some elements have still end up in the item class.
  • Null values become object. Replace them with the real type, made nullable, such as string? or int?.
  • Timestamps come out as string. Change them to DateTime or DateTimeOffset if the format is ISO 8601.
  • If a property named after a keyword looks odd, check it compiles. Capitalised names like Class are legal C#, but a rename may read better.

06Related concepts

DTO, System.Text.Json, auto-implemented properties, PascalCase, deserialization.

Frequently Asked Questions

What is JSON to C#?

JSON to C# is a free, browser-based developer tool on AIDToolStack. Convert JSON to C# classes It requires no installation or sign-up and works entirely in your browser.

Is JSON to C# free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON to C# store my data?

No. It runs in your browser; nothing is uploaded.

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe