JSON to C# Class Converter - Generate .NET Models Online

JSON to C# Class

Convert JSON to C# classes with System.Text.Json or Newtonsoft serialization.

Free online JSON to C# class converter. Paste any JSON payload, REST API response, webhook event, or JSON Schema specification to instantly generate clean, strongly typed C# class or record definitions for .NET 8, .NET 9, and legacy .NET Framework. Supports both modern System.Text.Json with [JsonPropertyName] attributes and Newtonsoft.Json (Json.NET) with [JsonProperty] annotations. Features C# 9+ immutable records with init-only properties ({ get; init; }), C# 8+ nullable reference types (string?, List<T>?), ISO-8601 DateTime parsing, and recursive nested class decomposition. Perfect for ASP.NET Core web APIs, microservices, Blazor, and MAUI apps. Runs 100% locally in your browser with zero server telemetry.

Keywords: json to c#, json to csharp, json to c# class, csharp class generator, json to dotnet, c# model from json, system.text.json, newtonsoft json class, c# serialization, json deserialize c# class, dotnet json class generator, json to record c#, c# json property name, json to c# converter online, csharp dto generator, json to csharp model, c# nullable reference types json, asp net core json model generator

Tags: json, csharp, dotnet, class, model, converter, generator, c#, record, system.text.json

Browse all 44 Developer Tools tools →

How to JSON to C# Class Online

  1. Paste JSON Payload or JSON Schema: Paste your sample JSON object, REST API response, webhook payload, array slice, or JSON Schema Draft-07 specification into the input editor.

  2. Set Root Model Identifier: Enter a PascalCase identifier for your top-level C# class or record (e.g., "UserProfile", "OrderEnvelope", "MetricsReport").

  3. Select Target Serializer: Choose between high-performance System.Text.Json (using [JsonPropertyName]) or legacy Newtonsoft.Json (using [JsonProperty]).

  4. Configure Records & Nullable Reference Types: Toggle C# 9+ immutable records with init-only setters ({ get; init; }) and C# 8+ nullable reference types (#nullable enable).

  5. Generate C# Models: Click "Generate C#" or press ⌘↵ (Ctrl+Enter on Windows/Linux) to instantly compute class hierarchies, nested types, and property mappings.

  6. Copy & Integrate: Copy the generated C# code with ⌘⇧C or download the .cs file for immediate integration into your ASP.NET Core API, Blazor, or .NET microservice project.

JSON to C# Class Features

  • Modern System.Text.Json Serialization: Emits idiomatic `[JsonPropertyName("...")]` attributes adhering to modern .NET 6, 7, 8, and 9 standard library standards.

  • Legacy Newtonsoft.Json Support: Seamlessly switch to `[JsonProperty("...")]` attributes for existing .NET Framework or enterprise Json.NET codebases.

  • C# 9+ Immutable Record Types: Generates clean `public record Name` models with `{ get; init; }` properties for modern immutable data transfer objects (DTOs).

  • Sound Nullable Reference Types: Emits `#nullable enable` and `T?` annotations (`string?`, `double?`, `List<T>?`) to eliminate unexpected NullReferenceExceptions at runtime.

  • Recursive Nested Class Decomposition: Recursively parses nested JSON objects into independent PascalCase child classes referenced cleanly by parent models.

  • Automatic ISO-8601 Date Detection: Identifies standard ISO-8601 and RFC 3339 datetime strings, generating strongly typed `DateTime` properties and `using System;` imports.

  • Typed Generic Collections: Inspects JSON arrays of primitives or objects to generate typed `List<T>` properties with `System.Collections.Generic` imports.

  • JSON Schema Draft Ingestion: Ingests JSON Schema Draft-07 and 2020-12 specifications, respecting `required` arrays for nullable vs mandatory property typing.

  • C# Keyword & Member Collision Protection: Automatically escapes C# reserved keywords (e.g., `@event`, `@params`, `@class`) and resolves CS0542 enclosing class name collisions.

  • Structural Hierarchy Metrics: Calculates total generated class count, distinct field count, and maximum nesting depth for complex data models.

  • 100% In-Browser Privacy: All parsing, AST traversal, and code synthesis run client-side in your web browser. Zero JSON bytes are transmitted over the network.

  • Keyboard-Driven Workflow: High-speed developer controls with ⌘↵ for generation, ⌘⇧C for copying output, and ⌘⇧K for clearing inputs.

Supported Formats & Dialects

The JSON to C# Class supports 6 syntax formats and dialects for accurate parsing and processing.

System.Text.Json (`[JsonPropertyName("...")]`)
Standard high-performance serializer built into modern .NET BCL. Operates directly on UTF-8 streams with minimal heap allocation.
Newtonsoft.Json / Json.NET (`[JsonProperty("...")]`)
Classic de facto .NET serialization library providing rich legacy feature support, custom contract resolvers, and broad backward compatibility.
C# 9+ Immutable Records (`public record Name { get; init; }`)
Immutable reference types featuring value-based equality semantics, non-destructive mutation via with-expressions, and concise DTO definitions.
C# 8+ Nullable Reference Types (`#nullable enable` & `T?`)
Static compiler nullability tracking that distinguishes mandatory non-null fields (`string`) from optional or nullable fields (`string?`).
ISO-8601 & RFC 3339 DateTime Ingestion
Automatic detection of timestamp strings, mapping directly to .NET `DateTime` or `DateTimeOffset` types with built-in ISO-8601 serialization.
Polymorphic Type Handling (`[JsonPolymorphic]`)
.NET 7+ native polymorphic serialization supporting discriminated union payloads and custom `JsonConverter<T>` deserializers.
All Guides
web code

Generating TypeScript Types from JSON: Schemas, Interfaces & Zod

How to generate type-safe TypeScript interfaces, Zod runtime validation schemas, and JSON Schema definitions from arbitrary JSON payloads.

Read Field Manual
developer tools

Mastering JSON to C# Class Serialization: System.Text.Json, Records & .NET Best Practices

Learn how to convert JSON payloads into robust, idiomatic C# classes and records. Master System.Text.Json, JsonPropertyName, Newtonsoft.Json, nullable reference types, and custom converters.

Read Field Manual
developer tools

Mastering JSON to Dart & Flutter Serialization: Null Safety, json_serializable & Freezed

Learn how to convert JSON payloads into robust, null-safe Dart models for Flutter. Master manual factory constructors, json_serializable, build_runner, and Freezed.

Read Field Manual
developer tools

Mastering JSON to Go Struct Serialization: encoding/json, Struct Tags & Custom Unmarshaling

Learn how to convert JSON payloads into robust, idiomatic Go structs. Master struct tags, omitempty edge cases, pointer nullability, and custom unmarshaling.

Read Field Manual
developer tools

Mastering JSON to Rust Struct Serialization: Serde, Derives & Zero-Copy Parsing

Learn how to convert JSON payloads into robust, idiomatic Rust structs with Serde. Master derive macros, Option<T> nullability, rename_all, and zero-copy deserialization.

Read Field Manual
text data

Runtime Schema Validation: Converting JSON to Zod for Type-Safe TypeScript APIs

Bridge the gap between compile-time TypeScript interfaces and runtime boundary validation. Learn how to generate, refine, and enforce Zod schemas from JSON payloads.

Read Field Manual
All Standards

Pre-built Automation Pipelines

Chain JSON to C# Class with other utilities in a multi-step visual workflow.

beginner
encoding

Base64 Decode → JSON Format

Decode a Base64 string and pretty-print the JSON inside it.

Flow:
InputBase64 Encode/DecodeJSON FormatterOutput
4 nodes
beginner
data-transformation

CSV → JSON → YAML

Convert CSV data to JSON, then to YAML format.

Flow:
InputCSV to JSONYAML ConverterOutput
4 nodes
intermediate
development

JSON Format → TypeScript Schema

Format JSON and generate TypeScript/Zod schema from it.

Flow:
InputJSON FormatterJSON to TypeScript & Schema GeneratorOutput
4 nodes

Frequently Asked Questions

How does System.Text.Json deserialize JSON into typed C# classes and records?
System.Text.Json operates on UTF-8 byte buffers (`ReadOnlySpan<byte>`) using an internal `Utf8JsonReader`. When `JsonSerializer.Deserialize<T>()` is called, it inspects the target type via reflection or pre-generated source generator metadata (`[JsonSerializable]`). It matches JSON keys against property names or `[JsonPropertyName]` attributes, constructs the target instance, converts primitive tokens into strongly typed C# values, and recursively populates child objects and generic `List<T>` collections.
What are the key differences between System.Text.Json and Newtonsoft.Json (Json.NET)?
System.Text.Json is built into the .NET runtime (starting in .NET Core 3.0) and is engineered for high throughput, minimal allocations, and Native AOT compatibility. Newtonsoft.Json is a third-party NuGet package with extensive features (e.g., deep JSONPath querying, flexible type converters, cyclic reference handling). For all new .NET 6, 7, 8, and 9 projects, System.Text.Json is Microsoft’s recommended choice.
When should you choose C# 9+ record over a mutable class for JSON DTOs?
Use `record` (or `record class`) with `{ get; init; }` properties when modeling API request/response contracts, webhook envelopes, and messaging payloads where data should remain immutable after deserialization. Records provide value-based equality (`==` compares field values rather than memory pointers), built-in formatting (`ToString()` displays all property values), and concise non-destructive cloning via `with` expressions.
How does the generator handle Nullable Reference Types (#nullable enable) and optional fields?
When Nullable Reference Types are enabled, the generator prepends `#nullable enable` and marks optional or null-bearing fields with `?` (e.g., `string?`, `double?`, `List<T>?`). Non-nullable reference types (`string`) indicate required fields, prompting compiler warnings if left unassigned, while nullable properties explicitly communicate that `null` or omission is valid.
Why are C# properties generated in PascalCase and annotated with [JsonPropertyName]?
Microsoft .NET Framework Design Guidelines mandate that all public properties, methods, and classes use `PascalCase` (e.g., `UserId`, `CreatedAt`). Because external JSON APIs frequently use `snake_case` or `camelCase`, the generator applies `[JsonPropertyName("user_id")]` or `[JsonProperty("user_id")]` attributes to preserve idiomatic C# casing while ensuring flawless JSON serialization.
How does the converter infer and map JSON numeric types (double vs int vs decimal)?
RFC 8259 specifies that all JSON numbers are arbitrary-precision decimal numbers without explicit distinction between floats and integers. By default, the generator maps numbers to `double` (or `double?` for nullable fields) to prevent truncation of floating-point values. In your .NET project, you can refine fields to `int`, `long`, or `decimal` for financial calculations where high-precision decimal arithmetic is required.
How does the converter decompose deeply nested JSON objects into separate C# classes?
Rather than generating deeply nested inline structures, the converter recursively walks the JSON AST. Each nested object and array item is extracted into a standalone, top-level PascalCase class or record named after its hierarchy (e.g., `OrderEnvelope`, `OrderEnvelopeCustomer`, `OrderEnvelopeCustomerAddress`). The parent class references the child type cleanly, resulting in reusable and maintainable C# code.
Can this tool generate C# models directly from JSON Schema specifications?
Yes. When you paste a JSON Schema Draft-07 or Draft 2020-12 specification containing `$schema` and `properties`, the converter parses the schema contracts. It evaluates the `required` array to determine non-nullable vs nullable properties, maps primitive schema types (`string`, `integer`, `number`, `boolean`) to corresponding C# types, and outputs ready-to-compile classes.
How do you implement polymorphic deserialization with [JsonPolymorphic] and [JsonDerivedType] in .NET?
In .NET 7 and later, System.Text.Json provides built-in polymorphic type handling. By decorating a base class or record with `[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]` and adding `[JsonDerivedType(typeof(SubClass), "sub_type_name")]` attributes, the serializer automatically inspects the discriminator field in JSON and instantiates the matching concrete subclass.
How are ISO-8601 date and timestamp strings handled with DateTime in C#?
The generator detects strings matching standard ISO-8601 and RFC 3339 date/time formats (e.g., `"2026-09-06T12:00:00Z"`) and maps them to `DateTime` (or `DateTime?` when nullable), including `using System;` at the top of the file. System.Text.Json natively parses standard ISO-8601 strings into `DateTime` and `DateTimeOffset` without requiring custom converters.
How can you deserialize JSON with custom date formats or Unix epochs using JsonConverter<T>?
If an API returns Unix epoch seconds as a numeric timestamp or non-standard date strings, you can create a custom converter by subclassing `JsonConverter<DateTime>`. In the converter, override `Read()` to parse `reader.GetInt64()` using `DateTimeOffset.FromUnixTimeSeconds()` and override `Write()` to write out the numerical epoch value.
Is any JSON payload or sensitive data sent to an external server during C# model generation?
No. The JSON to C# Class Converter runs 100% client-side in your web browser using JavaScript. Your JSON payloads, API response samples, proprietary schema files, and authorization data never leave your local device and are never transmitted to any server.

Developer Reference & Learning Hubs