JSON to C#
Generate C# classes or records from JSON with System.Text.Json or Newtonsoft attributes, nullable types like long?, and required members.
Local workspace
Named projects in IndexedDB · Local only — never synced to our servers. Worksp…
Batch workspace
Format multiple files locally in one run.
C# models for JSON have to agree with the serializer on names, nullability, and which members must be present. This generator merges every item of an array to find properties that can be missing or null, and makes them long?, double?, or string?. It marks the rest as required so .NET 7+ reports missing data instead of leaving defaults, adds [JsonPropertyName] or [JsonProperty] wherever the PascalCase name differs from the key, and avoids the CS0542 clash when a key matches its class name. Choose records for immutable models.
Common errors and fixes
The JSON value could not be converted to System.Int32
System.Text.Json found a string or a decimal where an int is declared. The generator uses long and double; if you changed a type, match the payload or set JsonNumberHandling.
JSON deserialization for type 'Root' was missing required properties
A required property's key is absent from the JSON. Include a sample without that key so the property is generated as nullable, or make sure the producer sends it.
CS8618: Non-nullable property must contain a non-null value when exiting constructor
Nullable reference types are enabled and a property may never be set. Mark it required, as the generator does, or make it nullable.
CS0542: member names cannot be the same as their enclosing type
A JSON key matches the class name. The generator renames the member with a Value suffix and maps it back with the attribute.
Options
| Option | Description |
|---|---|
| Serializer | Chooses between [JsonPropertyName] from System.Text.Json and [JsonProperty] from Newtonsoft.Json. |
| Type | Records with init accessors are immutable after deserialization. |
| Root name | Name of the top-level type. Nested types are named after their JSON keys. |
FAQ
System.Text.Json or Newtonsoft.Json: which should I choose?
System.Text.Json ships with .NET, is faster, and is the default in ASP.NET Core. Newtonsoft.Json is more lenient and has more features, and many older projects already depend on it. The choice only changes the attribute on renamed properties.
Why do properties have a JsonPropertyName attribute?
System.Text.Json matches property names case-sensitively unless you configure a naming policy, so FirstName wouldn't bind to first_name on its own. The attribute keeps the mapping explicit wherever the C# name differs from the key.
Why are some properties long? or string??
The key is missing from some samples or holds null. long? is a nullable value type, and string? is a nullable reference type, which matters when nullable reference types are enabled.
What does the required modifier do?
Since C# 11, a required member must be set when the object is created, and System.Text.Json on .NET 7+ throws if its key is missing from the JSON. The generator marks non-nullable reference properties as required.
Why was a property renamed to something like RootValue?
A member can't have the same name as its enclosing type (compiler error CS0542). The generator adds a Value suffix and keeps the original key in the attribute.