JSON to C# Class
Convert JSON to C# POCO classes or record types with JsonPropertyName attributes. Handles nested objects, arrays, and all C# primitive types.
What Is the JSON to C# Class Generator?
The JSON to C# class generator converts a JSON object into ready-to-use C# class definitions. Choose between POCO (Plain Old CLR Object) classes with auto-properties and C# record types with positional parameters. The tool adds [JsonPropertyName] attributes automatically when property names differ from JSON keys.
This tool is useful when building .NET REST clients, scaffolding model classes from API responses, or mapping JSON payloads to strongly-typed C# objects for use with System.Text.Json.
How to Use the JSON to C# Generator
- Paste your JSON object into the left panel, or click Load Sample.
- Set the root class name (defaults to Root).
- Choose POCO class or record mode using the toggle.
- The generated C# code appears on the right with required
usingstatements. - Click Copy to copy all class definitions.
Features
- Generates POCO classes with
{ get; set; }auto-properties - Generates C# record types with positional constructor syntax
- Adds
[JsonPropertyName("key")]when JSON key differs from PascalCase property name - Handles nested objects — each becomes a separate named class
- Maps JSON arrays to List<T> with inferred element type
- Type mapping: string →
string, boolean →bool, integer →int, decimal →double, null →object? - Includes
using System.Collections.Genericandusing System.Text.Json.Serialization - Configurable root class name
FAQ
What is a POCO class in C#?
POCO stands for Plain Old CLR Object. It is a simple C# class with no framework dependencies. A POCO class typically has public properties with getters and setters, making it straightforward to serialize and deserialize with System.Text.Json or Newtonsoft.Json.
What is a C# record?
C# records are reference types introduced in C# 9 that provide value-based equality and immutability by default. Positional records use a concise constructor syntax and are ideal for DTOs (Data Transfer Objects) because they are immutable and work well with pattern matching.
How are JSON types mapped to C# types?
JSON strings → string, booleans → bool, integers → int, floats → double, arrays → List<T>, objects → named class, null → object?.
Why does the generator add [JsonPropertyName] attributes?
C# property names use PascalCase by convention, but JSON keys often use camelCase. When a JSON key differs from its PascalCase equivalent, the generator adds [JsonPropertyName("originalKey")] so System.Text.Json correctly maps the JSON field during deserialization.