← Tools Home|

JSON to C# .NET Record & Class Generator (System.Text.Json & Newtonsoft)

100% Client-Side

Convert JSON payloads into strongly typed C# records, classes, and structs supporting System.Text.Json [JsonPropertyName] and Newtonsoft.Json attributes.

Generated C# Code
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace GeneratedModels
{
    public record OrderPayload
    {
        [JsonPropertyName("orderId")]
        public string? OrderId { get; init; }
    
        [JsonPropertyName("customer")]
        public Customer? Customer { get; init; }
    
        [JsonPropertyName("items")]
        public List<Item?>? Items { get; init; }
    
        [JsonPropertyName("billingAddress")]
        public BillingAddress? BillingAddress { get; init; }
    
        [JsonPropertyName("totalAmount")]
        public double TotalAmount { get; init; }
    
        [JsonPropertyName("currency")]
        public string? Currency { get; init; }
    
        [JsonPropertyName("isDelivered")]
        public bool IsDelivered { get; init; }
    
        [JsonPropertyName("deliveryNotes")]
        public object? DeliveryNotes { get; init; }
    }

    public record BillingAddress
    {
        [JsonPropertyName("street")]
        public string? Street { get; init; }
    
        [JsonPropertyName("city")]
        public string? City { get; init; }
    
        [JsonPropertyName("stateOrProvince")]
        public string? StateOrProvince { get; init; }
    
        [JsonPropertyName("postalCode")]
        public string? PostalCode { get; init; }
    
        [JsonPropertyName("country")]
        public string? Country { get; init; }
    }

    public record Item
    {
        [JsonPropertyName("sku")]
        public string? Sku { get; init; }
    
        [JsonPropertyName("name")]
        public string? Name { get; init; }
    
        [JsonPropertyName("quantity")]
        public int Quantity { get; init; }
    
        [JsonPropertyName("unitPrice")]
        public double UnitPrice { get; init; }
    
        [JsonPropertyName("discounts")]
        public List<int>? Discounts { get; init; }
    
        [JsonPropertyName("inStock")]
        public bool InStock { get; init; }
    }

    public record Customer
    {
        [JsonPropertyName("id")]
        public int Id { get; init; }
    
        [JsonPropertyName("fullName")]
        public string? FullName { get; init; }
    
        [JsonPropertyName("email")]
        public string? Email { get; init; }
    
        [JsonPropertyName("isPremiumMember")]
        public bool IsPremiumMember { get; init; }
    
        [JsonPropertyName("registeredAt")]
        public DateTimeOffset RegisteredAt { get; init; }
    }
}
Generated Classes/Records
4 records
Total Properties
24 properties mapped
JSON Payload Size
.NET 8+ / C# 12 ready
Technical Reference & Architecture Guide

JSON to C# .NET Record & Class Generator (System.Text.Json & Newtonsoft) — Reference Guide

Convert JSON payloads into strongly typed C# records, classes, and structs supporting System.Text.Json [JsonPropertyName] and Newtonsoft.Json attributes.

Key Parameters & Controls

targetTypestring (enum: record | class | struct)

Defines the C# declaration model. 'record' outputs immutable positional records with init-only setters, 'class' generates standard reference types, and 'struct' produces lightweight value types.

serializerLibrarystring (enum: System.Text.Json | Newtonsoft.Json | None)

Selects the serialization attribute set to decorate properties with, such as [JsonPropertyName("...")] for modern .NET or [JsonProperty("...")] for Json.NET.

nullabilityHandlingstring (enum: nullableReferenceTypes | optionalPrimitives | nonNullable)

Configures C# 8+ Nullable Reference Types (NRT) formatting, marking absent or null JSON attributes with '?' (e.g., string?, int?) or strictly non-nullable types.

namingConventionstring (enum: PascalCase | camelCase | preserve)

Determines how property names are formatted in generated C# symbols while mapping the original JSON key via serialization attributes.

Pro Tips & Best Practices

Common Gotchas & Troubleshooting

System.Text.Json throws JsonException: 'The JSON value could not be converted' on empty string values for numeric or DateTime fields.

Add custom JsonConverter implementations (such as a lenient int or DateTime converter) or configure the generator to emit nullable types (int?, DateTime?) along with an empty string pre-parser or custom `JsonConverter<T>`.

Generated C# class names collide when parsing nested JSON arrays containing anonymous sub-objects with identical key names.

Enable hierarchical type prefixing or namespace scoping in the generator settings to assign unique type identifiers (e.g., OrderBillingAddress vs. UserBillingAddress) instead of generic collision suffixes.

Properties with reserved C# keywords (e.g., 'params', 'class', 'event', 'object') cause compiler errors in generated code.

Escape reserved identifier names using the '@' prefix (e.g., `@class`, `@event`) while preserving the exact JSON mapping inside `[JsonPropertyName("class")]` or `[JsonProperty("class")]`.

Frequently Asked Questions

▼

▼

▼

▼

Related Tools & Utilities

All Tools →