JSON to C# Model Generator — Convert JSON to C# Classes Online

Automatically generate C# POCO classes and data models from standard JSON objects.

Privacy note: All processing happens entirely in your browser. No data is sent to our servers.

About this tool

The JSON to C# Model Generator converts any JSON object into ready-to-use C# class definitions. Paste your JSON and get strongly-typed C# POCO (Plain Old CLR Object) classes with correct property types, handling nested objects, arrays, and nullable types automatically.

This saves hours of manual model writing when integrating REST APIs into .NET applications. The generated classes work directly with System.Text.Json, Newtonsoft.Json, and ASP.NET Core model binding.

How to use

  1. Paste any valid JSON into the input — an API response, a config file, or any JSON structure.
  2. The tool generates C# class definitions matching the JSON structure.
  3. Copy the generated classes into your .NET project.
  4. Add the appropriate using statements: using System.Text.Json.Serialization; or using Newtonsoft.Json; depending on your serialiser.
  5. For API responses, use the root class name in your HttpClient.GetFromJsonAsync<RootClass>() call.

This page is available at /tools/json-to-csharp-model/.

Understanding the result

  • JSON strings become C# string properties.
  • JSON numbers without decimals become int or long.
  • JSON numbers with decimals become double or decimal.
  • JSON true/false values become bool.
  • JSON arrays become List<T> where T is the array item type.
  • Nested JSON objects become separate C# classes.
  • JSON null values generate nullable types (string?, int?).
  • Property names are converted from camelCase (JSON) to PascalCase (C# convention) with a [JsonPropertyName] attribute preserving the original JSON name.

FAQ

Can I use the generated classes with System.Text.Json?

Yes. The generated classes include [JsonPropertyName] attributes compatible with System.Text.Json (.NET 5+). For Newtonsoft.Json, the same attributes work or you can use [JsonProperty] instead.

What happens with JSON arrays of mixed types?

JSON arrays with mixed types (e.g. [1, "hello", true]) are uncommon in well-designed APIs but map to List<object> in C#. If possible, redesign the JSON to use consistent types within arrays.

Does it generate data annotations for validation?

The basic generator produces clean POCO classes. For ASP.NET Core model validation, manually add [Required], [MaxLength], [Range] and other attributes from System.ComponentModel.DataAnnotations after generation.

Can I convert the generated classes back to JSON?

Yes. Use JsonSerializer.Serialize(myObject) with System.Text.Json or JsonConvert.SerializeObject(myObject) with Newtonsoft.Json. The property attributes ensure the output JSON matches the original structure.