JSON to C# Class

Generate C# class definitions from JSON. Supports nested objects, arrays, namespaces, JsonPropertyName attributes, nullable types, and record syntax.

Input data is processed in your browser
Data is never sent to a server

Tool

Root class name
Namespace
Indent:

or drag & drop a file

What is the JSON to C# Class Converter?

This tool generates C# class definitions from JSON — ideal for quickly creating model classes from API responses, configuration files, or any JSON data structure.

Nested objects are expanded into separate named classes, arrays are typed as List<T>, and all classes are output in dependency order. Support for [JsonPropertyName], nullable reference types, and record syntax makes the generated code ready to drop into ASP.NET Core, MAUI, or any modern C# project.

How to Use

  1. Paste your JSON into the left panel. C# class definitions are generated instantly on the right. Click "Sample" to see an example.
  2. Enter a class name in the "Root class name" field (default: Root).
  3. Enter a C# namespace in the "Namespace" field (e.g. MyApp.Models).
  4. Enable "Use [JsonPropertyName]" to add `[JsonPropertyName]` attributes when the JSON key differs from the property name (System.Text.Json).
  5. Enable "Use nullable types (?)" to generate properties as nullable types with `?`.
  6. Enable "Use record instead of class" to output `record` syntax with `{ get; init; }` properties (requires C# 9+).

FAQ

How are nested objects handled?

Each nested object is converted into its own named C# class and referenced as a property type in the parent class. Classes are output in dependency order so the result can be pasted directly into a C# file.

How are arrays handled?

Arrays are typed as `List<T>`. For arrays of objects, all keys across all elements are merged into a single class and output as `List<ClassName>`.

What is the difference between record and class?

When "Use record" is enabled, properties use `{ get; init; }` instead of `{ get; set; }`, making instances immutable after creation. This requires C# 9 or later.

Does this support Newtonsoft.Json (Json.NET)?

This tool generates System.Text.Json `[JsonPropertyName]` attributes. If you need Newtonsoft.Json `[JsonProperty]`, change the attribute name after generating.