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
Popular Developer Tools tools
- JWT DecoderDecode, inspect, and validate JWT tokens with claim and signature analysis.
- Cron ParserParse, validate, explain, and build cron expressions with next run times and visual timeline.
- Regex TesterTest, debug, and explain regular expressions with real-time match highlighting.
- Regex ExplainerBreak down any regex into plain English, token by token.
- AI Token CounterCount tokens and estimate API costs for 100+ LLMs with exact BPE and provider tokenization.
How to JSON to C# Class Online
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.
Set Root Model Identifier: Enter a PascalCase identifier for your top-level C# class or record (e.g., "UserProfile", "OrderEnvelope", "MetricsReport").
Select Target Serializer: Choose between high-performance System.Text.Json (using [JsonPropertyName]) or legacy Newtonsoft.Json (using [JsonProperty]).
Configure Records & Nullable Reference Types: Toggle C# 9+ immutable records with init-only setters ({ get; init; }) and C# 8+ nullable reference types (#nullable enable).
Generate C# Models: Click "Generate C#" or press ⌘↵ (Ctrl+Enter on Windows/Linux) to instantly compute class hierarchies, nested types, and property mappings.
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.
In-Depth Technical Guides
All GuidesGenerating 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.
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.
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.
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.
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.
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.
Related Standards & RFC Specifications
All StandardsC# classes and record types define typed data models in .NET. Learn how System.Text.Json, Newtonsoft.Json, attributes, and records enable robust JSON serialization.
camelCase is a compound word writing convention where each constituent word begins with a capital letter without delimiter spaces, standard in JavaScript and modern software.
Go structs define typed data models in Golang. Learn how struct tags, encoding/json, omitempty, and pointers enable robust JSON serialization.
JSON is an open, text-based data interchange format standardized in RFC 8259, designed for human-readable and machine-parseable data transmission.
JSON Schema is a declarative JSON dialect for annotating, validating, and establishing structural contracts for JSON documents and REST APIs.
Serde is the de facto serialization and deserialization framework for Rust, enabling fast, zero-copy, compile-time data format translation.
Pre-built Automation Pipelines
Chain JSON to C# Class with other utilities in a multi-step visual workflow.
Base64 Decode → JSON Format
Decode a Base64 string and pretty-print the JSON inside it.
CSV → JSON → YAML
Convert CSV data to JSON, then to YAML format.
JSON Format → TypeScript Schema
Format JSON and generate TypeScript/Zod schema from it.
Example Input & Output
Sample ReferenceInteractive Example: JSON to C# Class in ActionShow example
Sample Input (text)
{
"id": 101,
"username": "johndoe",
"email": "[email protected]",
"is_active": true,
"created_at": "2026-09-06T08:30:00Z",
"roles": [
"Admin",
"Developer"
]
}Sample Output
[Processed output for JSON to C# Class]
Input transformed successfully using json to c#, json to csharp, json to c# class.What happened:
Convert JSON to C# classes with System.Text.Json or Newtonsoft serialization.
Pairwise Format Converters
All ConvertersConvert JSON to C# Classes (System.Text.Json)
Free, 100% client-side private JSON to C# Classes (System.Text.Json) converter. Transform syntax instantly in your browser with zero data logging, strict AST validation, and CLI support.
Convert YAML to C# Classes (System.Text.Json)
Free, 100% client-side private YAML to C# Classes (System.Text.Json) converter. Transform syntax instantly in your browser with zero data logging, strict AST validation, and CLI support.
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.
Related Developer Tools
- JSON to TypeScriptConvert JSON to TypeScript interfaces or type aliases instantly.
- JSON to Go StructConvert JSON to Go structs with json tags and idiomatic naming.
- JSON to Rust StructConvert JSON into idiomatic Rust structs with Serde Serialize and Deserialize derive macros.
- JSON to Zod SchemaConvert JSON to Zod schema definitions with automatic TypeScript type inference.
- JSON to Pydantic ModelConvert JSON and JSON Schema into typed Pydantic v2 and v1 BaseModel classes for FastAPI, Django Ninja, and Python applications.
- JSON to DartConvert JSON to null-safe Dart classes with json_serializable & fromJson constructors.
- JSON to TypeScript & Schema GeneratorGenerate TypeScript interfaces, Zod schemas, and Valibot schemas from JSON.
- JSON Repair ToolRepair and fix malformed JSON data from AI outputs, API responses, and copy-paste.
- JSON FormatterPrettify, minify, and validate JSON data instantly.
- cURL to Code ConverterConvert cURL commands to idiomatic code across 14 programming languages instantly.
- YAML ConverterConvert between JSON and YAML with validation, formatting, and multi-document support.
- Text Diff CheckerCompare two text blocks and highlight exactly what changed.