JSON to C# Class Generator

Generate C# class definitions from JSON with proper type inference, JsonPropertyName attributes, and nullable reference types.

What is JSON to C# Class Generator?

This tool converts JSON data into C# class definitions with proper type inference. It generates properties with { get; set; } accessors, converts field names to PascalCase following C# conventions, supports nullable reference types, and can add System.Text.Json attributes for JSON serialization.

How to Use

  1. Set the root class name and configure options (nullable types, System.Text.Json attributes, date detection)
  2. Paste your JSON data into the input area
  3. Click "Generate C# Classes" and copy the output into your C# project

Why Use This Tool?

Automatically infer C# types from JSON values (int, double, string, bool, DateTime, List<T>)
Convert field names to PascalCase following C# naming conventions
Generate nested classes with correct ordering (children first)
Support nullable reference types for null-safe code
Add JsonPropertyName attributes for proper JSON key mapping

Tips & Best Practices

  • Use realistic sample data — type inference depends on actual values
  • Enable nullable types for modern C# projects (C# 8.0+)
  • System.Text.Json attributes ensure JSON keys match original names even after PascalCase conversion
  • Null values in JSON are converted to nullable types (int?, double?, etc.)

Frequently Asked Questions

How are JSON types mapped to C#?

JSON strings → string, integers → int, floats → double, booleans → bool, null → T? (nullable), arrays → List<T>, objects → separate nested classes. ISO-8601 date strings can be detected as DateTime when the option is enabled.

Why use PascalCase for property names?

C# convention requires public properties to use PascalCase. This tool automatically converts camelCase, snake_case, or kebab-case field names to PascalCase while preserving the original JSON key in the JsonPropertyName attribute.

What does the "Nullable types" option do?

When enabled, value types (int, double, bool, DateTime) are generated as nullable (int?, double?, bool?, DateTime?) for fields that may have null values. This is useful for APIs where fields can be omitted or null.

What are System.Text.Json attributes?

The [JsonPropertyName("key")] attribute tells System.Text.Json to map a C# property to a specific JSON key. This is essential when C# PascalCase property names differ from the original camelCase JSON keys.

Is my data sent to a server?

No, all processing happens entirely in your browser. Your JSON data never leaves your device.

Related Tools