JSON to C# Class

Generate C# class definitions from JSON data — with properties, attributes, and nullable types

  1. Home
  2. /
  3. JSON to C# Class

Options

Generated C# Code

using System.Text.Json.Serialization;

public class User
{
    [JsonPropertyName("id")]
    public int Id { get; set; }

    [JsonPropertyName("name")]
    public string? Name { get; set; }
}

Classes

0

Properties

0

Nullable

-

Nesting

0

What Is a C# POCO?

A POCO (Plain Old CLR Object) is a simple C# class with auto-implemented properties. It's the foundation for data transfer objects, entity models, and API response models in .NET applications. With JSON serialization attributes, you can control property naming during serialization.

How to Use

  1. Paste JSON — Enter valid JSON data.
  2. Set class & namespace — Customize the output.
  3. Toggle options — JsonPropertyName attributes, nullable types.
  4. Copy or download — Save as .cs file.

Frequently Asked Questions

What .NET versions are compatible with the generated code?

The generated C# classes use modern syntax compatible with .NET 5+ and .NET Core 3.1+. The JsonPropertyName attribute requires System.Text.Json which is included in .NET Core 3.0 and later. For older .NET Framework projects, you can disable the attribute option.

What is JsonPropertyName and when should I use it?

JsonPropertyName is an attribute from System.Text.Json.Serialization that maps C# property names to their JSON key equivalents. Use it when your JSON keys use different casing conventions than your C# properties (e.g., JSON has first_name but C# uses FirstName).

How are nullable reference types handled?

When nullable reference types are enabled, value-type properties (int, DateTime, etc.) become nullable with ? suffixes (e.g., int?). Reference-type properties like string also get the nullable annotation. This requires a nullable-enabled project context.

Does the generator handle nested JSON objects?

Yes. Nested objects are generated as separate classes within the same namespace. Each nested class has its own properties, and the parent class references the nested class as a property type.

Can I use this with Newtonsoft.Json instead of System.Text.Json?

Yes. Simply disable the JsonPropertyName option and add your own Newtonsoft attributes like [JsonProperty("name")] manually. The core class structure and property definitions remain the same.

Last updated: 9 Jul 2026