JSON to C#

Generate C# classes or records for System.Text.Json or Newtonsoft.Json

JSON input

Options

Model
Type style
Serialization

C# output

Paste JSON or load an example to generate C# code.

What JSON to C# generates

JSON to C# turns an API response or any JSON sample into C# types in one file with a file-scoped namespace. Class mode writes { get; set; } properties; Record mode writes positional records and places attributes on the generated properties with [property: ...]. System.Text.Json uses [JsonPropertyName("key")] and Newtonsoft.Json uses [JsonProperty("key")]. A property never gets its enclosing type's name, which C# does not allow.

How to use
  1. 1.Paste JSON, upload or drop a .json file, or load one of the examples.
  2. 2.Set the root type name and optional namespace such as Company.Project.Models.
  3. 3.Choose the type style, property naming and nullable reference types.
  4. 4.Choose the serializer and attribute policy, then copy the code or download <Root>.cs.
How types are inferred
  • •Every array item is inspected, not just the first one, and objects in the same array are merged.
  • •A key missing from some objects is optional; a key that is sometimes null is nullable. The two are kept apart.
  • •1 and 2.5 in the same position widen to a decimal number; other mixes are reported.
  • •Empty arrays and values that are only ever null have no type evidence, so a generic type is used and a note explains why.
  • •Type mapping: string → string, integer → int, long, ulong or decimal by range, decimal → double, boolean → bool, array → List<T>, object → class or record, missing or null → T?, unknown or mixed → object.
  • •Required members need C# 11 / .NET 7 or later; System.Text.Json then rejects JSON that misses a required key.
Limits and privacy

A sample shows what the data looked like once, not the full API contract. Review optional fields, generic types and number widths before relying on the code. Input is limited to 5 MB and 256 nesting levels; from 2 MB, generation waits for the Generate button. Everything runs in your browser and the JSON is never uploaded. With System.Text.Json, object properties hold a JsonElement after deserialization.

CodingTool is officially live on

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.toolsLaunchpadly Startup DirectoryCodingTool.dev — Featured on Smol Launch