Zero Signup ToolsFree browser tools

Developer Tools

JSON to C# Class Converter

Convert JSON to C# classes or records in your browser. System.Text.Json or Newtonsoft attributes, nullable types, init setters, file-scoped namespaces.

0 chars

Output options

Live preview updates with every change. All parsing and inference run in your browser; the JSON you paste is not uploaded.

Used as the name of the top-level class or record. Normalised to a valid PascalCase C# identifier automatically.

File-scoped namespaces drop the curly braces and save a level of indentation. Available in C# 10 and later.

Declaration style

Class uses mutable auto-properties (get/set). Record uses init-only setters (immutable after construction). Positional records take constructor parameters and generate properties automatically.

Attribute style

Attributes are emitted only when the JSON key does not round-trip to the C# property name verbatim (snake_case, kebab-case, leading digits, or reserved words).

Integer type

JSON numbers without a fractional part. long is the safer default for IDs and Unix timestamps; int saves a few bytes per record.

Indent

Microsoft style guide and dotnet format both default to 4 spaces.

How to use

  1. Paste a JSON value into the input on the left, or click Load sample JSON to see a worked example.
  2. Pick a declaration style: Class for mutable DTOs, Record (init) for immutable modern DTOs, or Record (positional) for compact constructor-based types.
  3. Choose an attribute style (System.Text.Json, Newtonsoft.Json, or none). Attributes appear only when the JSON key does not match the C# property name exactly.
  4. Set the integer type (long for IDs and timestamps, int when you want compact memory), and toggle Use nullable reference types to match the <Nullable> setting in your csproj.
  5. Optionally wrap the output in a namespace using file-scoped syntax (C# 10+), add the required keyword on non-nullable properties (C# 11+), and switch between 2 and 4 space indentation.
  6. Click Copy C# to put the full output on your clipboard, ready to paste into a .cs file.

About this tool

JSON to C# Class Converter turns any JSON value into idiomatic C# type declarations entirely in your browser. Paste an API response, a config file, an HTTP fixture, or a copied object literal, and the tool parses it with the browser's native JSON parser, walks the resulting tree, and emits one named type per object shape with property names and types that match .NET conventions. Choose between three declaration styles to fit your codebase: a classic public class with mutable get/set auto-properties for legacy projects and EF Core models, a public record with init-only setters for immutable DTOs in modern .NET 5+ codebases, or a positional record with constructor parameters for compact value types. Properties are PascalCased per the Microsoft framework design guidelines, with common initialisms (Id, Url, Api, Http, Https, Ip, Json, Uri, Uuid, Db, Sdk) normalised to their canonical .NET casing (Id, not ID; Url, not URL) so user_id becomes UserId and api_url becomes ApiUrl. Whenever a JSON key does not round-trip to the C# property name verbatim (snake_case, kebab-case, leading digits, reserved words), the tool emits the right serialisation attribute automatically: [JsonPropertyName("original_key")] for System.Text.Json (the modern default that ships with .NET) or [JsonProperty("original_key")] for Newtonsoft.Json (still the most-used JSON library in the ecosystem). Numbers split into long (Int64) or int (Int32) for integers and double for anything with a fractional part, with the integer preference exposed as a toggle so you can match Unix timestamps and Twitter snowflake IDs without manual edits. Nullability is inferred: keys missing in some samples become nullable types (string?, int?, MyClass?), keys that ever saw JSON null are nullable as well, and value types receive Nullable<T> the C# way (int? is Nullable<int>). The nullable reference types toggle lines up with the &lt;Nullable&gt; setting in your csproj so the output drops into a strict project without warnings. Output options also cover namespace wrapping (with file-scoped syntax for C# 10 and later), 2 or 4 space indentation, A to Z property sorting versus original JSON insertion order, and the C# 11 required keyword for non-nullable properties so they must be set at construction. The right using statements (System.Collections.Generic, System.Text.Json.Serialization or Newtonsoft.Json) are added only when actually needed. Useful for typing API responses, scaffolding DTOs and view models, modelling third-party webhook payloads, generating record types for ASP.NET Core controllers and minimal APIs, prepping seed data for tests, and saving the boilerplate that every pull request adding a new endpoint would otherwise need. Parsing, inference, and code generation run locally on your device, so the JSON you paste here never leaves your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools