jsondecode.com logo

JSON to C# Class Generator — Free Online Tool

Convert JSON to C# class definitions with proper types, nullable annotations, and JsonProperty attributes using AI. Free, no sign-up.

JSON to BigQuery Schema Converter — Free Online ToolJSON to React Flow Diagram — Convert JSON Online FreeJSON to Go Struct with BSON Tags — Free Online ToolJSON to TypeScript Interface Generator — Free OnlineJSON to YAML Converter — Convert JSON to YAML OnlineJSON to CSV Converter — Export JSON Array to CSV FreeJSON to Python Dataclass Generator — Free Online ToolJSON to SQL INSERT Statement Generator — Free OnlineJSON to Markdown Table Converter — Free Online ToolJSON to XML Converter — Convert JSON to XML Online FreeJSON to HTML Table Converter — Free Online ToolYAML to JSON Converter — Convert YAML to JSON Online FreeXML to JSON Converter — Convert XML to JSON Online FreeJSON to JSON Schema Generator — Free Online ToolJSON to GraphQL Schema Generator — Free Online ToolRuby to JSON Converter — Convert Ruby Hashes to JSON OnlineJSON to Java Class (POJO) Generator — Free Online ToolJSON to Kotlin Data Class Generator — Free Online ToolJSON to Rust Struct Generator — Free Online ToolJSON to PHP Array Converter — Free Online ToolCSV to JSON Converter — Free Online ToolJSON to Dart Class Generator — Free Online ToolJSON to Swift Struct (Codable) Generator — Free OnlineJSON to Terraform HCL Variables Converter — Free OnlineJSON to Mongoose Schema Generator — Free Online ToolJSON to Prisma Schema Model Generator — Free OnlineJSON to Protocol Buffer (proto3) Generator — Free OnlineJSON to TOML Config Format Converter — Free Online ToolTOML to JSON Converter — Convert TOML to JSON Online FreeJSON to Apache Avro Schema Generator — Free Online ToolJSON to OpenAPI 3.0 Schema Component — Free Online ToolJSON to R Data Frame Code Generator — Free Online ToolJSON to Lua Table Syntax Converter — Free Online ToolJSON to Zod Schema (TypeScript) Generator — Free OnlineJSON to Scala Case Class with Circe Codec — Free OnlineJSON to PowerShell Hashtable Converter — Free Online Tool

JSON to C# Class Generator — Free Online Tool

About JSON to C# Class Generator — Free Online Tool

JSON to C# Class converts JSON objects into strongly-typed C# class definitions, automatically adding Newtonsoft.Json JsonProperty attributes and System.Text.Json JsonPropertyName attributes to map JSON keys to C# property names. Developers use it to eliminate hand-writing data transfer objects (DTOs), avoid typos in property mappings, and instantly scaffold model classes when consuming REST APIs or deserializing configuration files.

JSON to C# Type Mapping

JSON TypeJSON ExampleC# TypeNotes
string"hello"stringNullable as string? in C# 8+ nullable contexts
number (integer)42intLong integers map to long; tool infers from value range
number (float)3.14doubleUse decimal for financial data requiring exact precision
booleantrueboolNullable variant is bool?
nullnullobject?Or typed nullable e.g. string? when sibling values reveal type
object{"id":1}class (nested)Generates a new nested class definition
array of objects[{"id":1}]List<T>T is the generated nested class type
array of primitives[1,2,3]List<int>Element type matches JSON primitive mapping
empty array[]List<object>Falls back to object when element type cannot be inferred
date string"2024-01-15"string or DateTimeDateTime when format matches ISO 8601; string otherwise

Deserialization Library Attribute Comparison

FeatureNewtonsoft.Json (Json.NET)System.Text.Json (.NET 6+)ServiceStack.Text
Property name attribute[JsonProperty("key")][JsonPropertyName("key")][DataMember(Name="key")]
Ignore property[JsonIgnore][JsonIgnore][IgnoreDataMember]
Required property[JsonProperty(Required = Required.Always)][JsonRequired] (.NET 7+)N/A
Custom converter[JsonConverter(typeof(T))][JsonConverter(typeof(T))][JsConfig] static config
Null handlingNullValueHandling.IgnoreJsonIgnoreCondition.WhenWritingNullJsConfig.IncludeNullValues
Camel-case defaultCamelCasePropertyNamesContractResolverJsonSerializerOptions.PropertyNamingPolicyJsConfig.EmitCamelCaseNames
NuGet packageNewtonsoft.JsonBuilt into .NET 6+; System.Text.Json on olderServiceStack.Text
.NET version support.NET Framework 2.0+.NET Core 3.0+ / .NET 5+.NET Framework 3.5+

Frequently Asked Questions

How do I deserialize JSON to a C# class using Newtonsoft.Json?

Install the Newtonsoft.Json NuGet package, paste your generated class, then call JsonConvert.DeserializeObject<YourClass>(jsonString). The [JsonProperty] attributes on each property tell the deserializer how to map JSON keys that differ from the C# property names. For lists, use JsonConvert.DeserializeObject<List<YourClass>>(jsonString) when the root JSON value is an array.

What is the difference between JsonProperty and JsonPropertyName in C#?

[JsonProperty] belongs to Newtonsoft.Json (Json.NET) and has been the standard since .NET Framework days, supporting rich options like NullValueHandling and Required. [JsonPropertyName] belongs to System.Text.Json, the built-in serializer introduced in .NET Core 3.0 and the recommended choice for new .NET 6+ projects. Both attributes serve the same core purpose of mapping a JSON key name to a C# property name when they differ.

How do I handle nullable properties when converting JSON to C# class?

Enable C# 8+ nullable reference types in your project (add <Nullable>enable</Nullable> to your .csproj) and mark properties that can be null with a trailing ? (e.g., string? Description). For value types like int, use int? to allow null. With System.Text.Json, add [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] to omit null properties during serialization.

Can I convert nested JSON objects to C# classes automatically?

Yes — nested JSON objects generate separate nested class definitions, and the parent class holds a property typed to that child class. For example, a JSON object with an address field containing street and city keys produces both a root class with an Address property and a separate Address class. Arrays of objects generate a List<ChildClass> property and the corresponding child class definition.

Why does my JSON to C# conversion use object instead of a specific type?

Generators fall back to object when a JSON value is null and there are no other array elements or sibling values to infer the type from. To fix this, provide a sample JSON payload that includes a non-null representative value for those fields. Alternatively, manually replace object or object? with the correct type (e.g., string?, int?, List<OrderItem>) after generation.

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.