JSON to .NET DTO

Paste JSON and instantly generate C# Data Transfer Object classes or records for .NET Core.

JSON InputValid

Options

Generated C# Code
C# / .NET Core20 properties
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MyApp.Dto;

public class Root
{
    [JsonPropertyName("id")]
    public int Id { get; set; }
    [JsonPropertyName("firstName")]
    public string FirstName { get; set; }
    [JsonPropertyName("lastName")]
    public string LastName { get; set; }
    [JsonPropertyName("email")]
    public string Email { get; set; }
    [JsonPropertyName("isActive")]
    public bool IsActive { get; set; }
    [JsonPropertyName("balance")]
    public decimal Balance { get; set; }
    [JsonPropertyName("createdAt")]
    public DateTime CreatedAt { get; set; }
    [JsonPropertyName("tags")]
    public List<string> Tags { get; set; }
    [JsonPropertyName("address")]
    public Address Address { get; set; }
    [JsonPropertyName("orders")]
    public List<Order> Orders { get; set; }
}

public class Address
{
    [JsonPropertyName("street")]
    public string Street { get; set; }
    [JsonPropertyName("city")]
    public string City { get; set; }
    [JsonPropertyName("zipCode")]
    public string ZipCode { get; set; }
    [JsonPropertyName("country")]
    public string Country { get; set; }
}

public class Order
{
    [JsonPropertyName("orderId")]
    public int OrderId { get; set; }
    [JsonPropertyName("total")]
    public decimal Total { get; set; }
    [JsonPropertyName("status")]
    public string Status { get; set; }
}

What is JSON to .NET DTO?

A JSON to .NET DTO Generator is a code generation tool that takes a JSON object or array and automatically generates the corresponding C# class definitions (Data Transfer Objects) that map to that JSON structure. DTOs are plain classes used to represent data as it moves between layers of a .NET application — from an API controller to a service, or from a JSON response to a typed object in C#.

Writing DTO classes by hand from JSON responses is tedious and error-prone, especially for complex nested objects with many properties. You need to identify each field's name and data type, handle nullable types, deal with camelCase-to-PascalCase naming conventions, and create nested classes for embedded objects. The generator automates all of this, producing ready-to-use C# class definitions with correct property types and JsonPropertyName attributes.

This tool is used by .NET developers integrating with third-party REST APIs, converting JSON configuration files to typed classes, building microservices that communicate with JSON payloads, and generating models for Swagger-documented APIs where JSON schemas are available.

How to Use JSON to .NET DTO

  1. 1Step 1: Paste a sample JSON object or JSON array into the input area. The more complete and representative your sample JSON is (especially for nullable or optional fields), the better the generated classes will be.
  2. 2Step 2: Enter a root class name for the outermost object. The generator will use this name for the top-level class and derive names for nested classes from their JSON property names.
  3. 3Step 3: Select any options available, such as whether to generate JsonPropertyName attributes (for camelCase JSON with PascalCase C# properties), use nullable reference types, or add data annotations.
  4. 4Step 4: Click 'Generate' and review the output C# classes. Check that all properties have the correct types — strings, integers, booleans, DateTimes, nested objects, and arrays of objects or primitives.
  5. 5Step 5: Copy the generated C# code and add it to your .NET project. Verify the class compiles correctly and test it by deserializing your actual JSON using System.Text.Json or Newtonsoft.Json.

Benefits of Using JSON to .NET DTO

  • Massive Time Savings: Generating DTO classes from complex JSON with 20-30 properties takes seconds rather than the 10-30 minutes of manual typing required, with fewer typos and type errors.
  • Correct Type Inference: The generator analyzes JSON values to determine the most appropriate C# type — int vs long, decimal for numbers with decimal points, bool for true/false, and DateTime for ISO date strings.
  • Handles Nested Objects: Automatically generates separate C# classes for nested JSON objects and uses the correct class types for properties, handling deeply nested structures without manual work.
  • JSON Attribute Generation: Produces JsonPropertyName attributes or JsonProperty (Newtonsoft) attributes to correctly map camelCase JSON property names to PascalCase C# property names.
  • Reduces Integration Bugs: Auto-generated classes that accurately reflect the JSON schema reduce the risk of missing properties, wrong types, or misnamed fields that cause deserialization failures at runtime.
  • Rapid API Integration: When integrating a new third-party API, paste the example response from the API documentation and immediately have strongly-typed C# models ready for use in your application.

Example

A .NET developer is integrating with a weather API that returns a JSON response with 35 properties including nested location, current conditions, and hourly forecast arrays. Rather than manually writing the C# classes, they paste the JSON sample from the API documentation into the JSON to .NET DTO generator with the root class name 'WeatherResponse'. The generator produces a WeatherResponse class with a Location property of type LocationDto, a CurrentConditions property of type CurrentConditionsDto, and an HourlyForecasts property of type List<HourlyForecastDto>, along with all three nested classes with their correctly typed properties and JsonPropertyName attributes. The developer copies the code, adds it to their project, and the JSON deserializes correctly on the first try.

About JSON to .NET DTO

JSON to .NET DTO analyzes a JSON object and generates C# Data Transfer Object (DTO) class definitions with proper types, property names, and optional JsonPropertyName attributes. It saves significant time when building .NET APIs that consume or produce JSON. Paste JSON and copy ready-to-use C# code.

  • Generates C# class from JSON
  • Proper type inference for all values
  • Optional JsonPropertyName attributes
  • Handles nested objects and arrays