JSON to C# Class Generator

Paste JSON to generate C# class definitions with proper types, naming conventions, and serialization attributes.

About This Tool

Working with external APIs in .NET usually starts the same way: you get a JSON response and need matching C# classes before you can deserialize anything. Writing those classes by hand — figuring out which fields are nullable, nesting child objects, and getting the property names right — is tedious and error-prone. This tool does it for you in milliseconds.

Paste any JSON payload and the generator produces clean C# POCO classes ready for use with System.Text.Json or Newtonsoft.Json. Each JSON key is mapped to a PascalCase property following standard .NET naming conventions, and the original key name is preserved in a [JsonPropertyName("...")] attribute so deserialization works without extra configuration. Nested objects become their own class definitions, arrays are typed as List<T>, and primitive values map to string, int, double, or bool as appropriate.

Nullable reference types are supported out of the box. When a JSON value is null, the corresponding C# property is generated with the ? suffix — for example string? or int? — so your code compiles cleanly with <Nullable>enable</Nullable> in your project file. If you prefer C# 9+ record types over traditional classes, a toggle switches the output to public record declarations, which is handy for immutable DTOs.

If you are already using our JSON to TypeScript converter for front-end models, this tool gives you the same convenience on the .NET side. You can also validate your input first with the JSON Formatter, or generate a formal schema with the JSON Schema Generator if you need contract-first development.

All parsing and code generation runs entirely in your browser using JavaScript. No JSON data is transmitted to any server, logged, or stored. You can verify this yourself by opening the Network tab in DevTools while using the tool — there are zero outbound requests.

How to Use

  1. Paste or type your JSON into the JSON Input panel on the left side.
  2. The C# class output updates automatically in the right panel as you edit.
  3. Set the Root class name to customize the top-level class (defaults to "Root").
  4. Toggle Records to generate C# 9+ record types instead of traditional classes.
  5. Toggle Nullable to emit nullable reference types (string?, int?) for fields with null values.
  6. Choose your serialization framework — System.Text.Json attributes or Newtonsoft.Json [JsonProperty] attributes.
  7. Click Copy or press Ctrl+Shift+C to copy the generated C# code to your clipboard. Use Sample to load example JSON.

Popular JSON to C# Examples

View all 15 JSON to C# examples &rarr;

FAQ

How does the tool handle nested JSON objects?

Each nested object in the JSON input becomes a separate C# class definition. The class name is derived from the parent property key converted to PascalCase. For example, a JSON field called "billing_address" produces a class named BillingAddress with its own set of properties. Deeply nested structures are handled recursively, so you get a complete set of classes no matter how many levels deep the JSON goes.

Does the output work with System.Text.Json and Newtonsoft.Json?

Yes. You can select your preferred serialization library in the options. When System.Text.Json is selected, properties are annotated with [JsonPropertyName("...")]. When Newtonsoft.Json is selected, properties use [JsonProperty("...")]. Both preserve the original JSON key names so deserialization works correctly without custom converters.

How are nullable types handled?

When the nullable option is enabled, any JSON field with a null value generates a nullable C# type — for example, string? instead of string, or int? instead of int. This matches the behavior expected when <Nullable>enable</Nullable> is set in your .csproj file. Fields that have actual values in the JSON are generated as non-nullable by default.

What naming convention is used for properties?

All JSON keys are converted to PascalCase for the C# property name, following standard .NET conventions. A key like "first_name" becomes FirstName, "userEmail" becomes UserEmail, and "id" becomes Id. The original JSON key is always preserved in the serialization attribute so round-trip serialization works without manual mapping.

Can I generate record types instead of classes?

Yes. Enable the Records toggle to output C# 9+ record declarations (public record ClassName). Records are ideal for immutable data transfer objects since they provide value-based equality, built-in ToString() formatting, and with-expression support. The generated records use init-only properties, making them a good fit for API response models that shouldn't be mutated after deserialization.

Is my data safe?

Yes. The JSON you paste is parsed using the browser's built-in JSON.parse() function and the C# code is assembled from string templates in client-side JavaScript. Nothing leaves your browser — there are no API calls, no server-side processing, and no telemetry on your input data. You can confirm this by checking the Network tab in your browser's DevTools while using the tool.

How are JSON arrays mapped to C# types?

Arrays are mapped to List<T> where T is inferred from the first element. An array of strings becomes List<string>, an array of numbers becomes List<int> or List<double>, and an array of objects becomes List<ClassName> where ClassName is generated from the property key. Empty arrays default to List<object> since the element type cannot be determined from the input.

Related Tools