Free JSON to C# — class · record · STJ · Newtonsoft

Convert JSON to C#
class, record or
model. Instantly.

Generate C# classes, records and annotated models from any JSON. Plain class, System.Text.Json and Newtonsoft.Json styles. Nested objects, List<T> arrays, nullable types. Runs entirely in your browser.

Your data never leaves your browser
Plain class · Record · STJ · Newtonsoft
Nested objects → separate classes
Nullable reference types
Always free
JSON to C# Class Generator   100% client-side
Use a representative JSON sample with non-null values for accurate type inference. Null fields become object? — refine manually after generating.
JSON input
  C# class ready

      

Plain class vs Record vs STJ vs Newtonsoft

Choose the style that matches your .NET version and JSON library.

StyleRequirementsBest for
Plain class Any .NET / .NET Framework Maximum compatibility — works with any JSON library, any .NET version. Use as the base and add annotations manually.
C# Record C# 9+ · .NET 5+ Immutable API response models. Positional record syntax — concise, with built-in equality and ToString().
System.Text.Json .NET Core 3.0+ — no NuGet needed Modern .NET 6/7/8/9 projects. [JsonPropertyName] maps snake_case keys. Fastest built-in option.
Newtonsoft.Json NuGet: Newtonsoft.Json Legacy .NET Framework, older ASP.NET Core, or projects already using Newtonsoft. [JsonProperty] attribute.

How JSON types map to C# types

Type inference rules applied to each JSON value.

JSON valueC# typeNotes
"Alice"stringAll JSON strings become string.
42int / longValues ≤ int.MaxValue become int, larger become long.
98.5doubleAll floating-point numbers become double.
trueboolDirect mapping.
nullobject?Null → nullable object. Refine the type manually after generating.
["a","b"]List<string>Item type inferred from first element. Empty → List<object>.
[{…},{…}]List<ChildClass>Array of objects → separate class + typed List.
{…}ChildClassNested object → separate named class in PascalCase.

When do you need JSON to C# classes?

ASP.NET Core API responses

When consuming a third-party REST API in an ASP.NET Core application, you need a C# class for System.Text.Json or Newtonsoft to deserialise the response. Generate from the actual API response, choose your library style, and call JsonSerializer.Deserialize<T>(json) immediately.

Visual Studio paste special

Visual Studio has a built-in "Paste JSON As Classes" feature (Edit → Paste Special), but it only generates plain classes. This converter gives you the same result plus Record, System.Text.Json and Newtonsoft styles — directly in the browser without opening Visual Studio.

Blazor and MAUI

Blazor WebAssembly and .NET MAUI apps use System.Text.Json by default for HTTP responses. Generate the model class with STJ attributes to handle snake_case API keys automatically — without writing a custom JsonNamingPolicy.

.NET Framework migration

Migrating a legacy .NET Framework project that uses Newtonsoft.Json? Generate Newtonsoft-annotated classes from the API response JSON — then switch to System.Text.Json by regenerating with the STJ style when you upgrade to .NET 6+.

All json to code tools

C# classes generated
in your browser. No upload.

The entire class generation runs in JavaScript locally — your JSON API response is never transmitted to any server. The generated code follows C# conventions: PascalCase property names, correct nullable annotations, and the exact attribute syntax for each JSON library.

The output is immediately usable: add the namespace, paste into your Models folder, and call JsonSerializer.Deserialize<Root>(json). No additional configuration needed for standard JSON keys.

4 output styles

Plain class, Record, System.Text.Json and Newtonsoft.Json — covering every .NET version from .NET Framework 4.5 to .NET 9.

Nested classes

Each nested JSON object generates a separate named class — no Dictionary<string, object> shortcuts. Fully typed from root to leaf.

Nullable reference types

Optional nullable annotations for C# 8+ projects — marks string and reference type properties as nullable where the JSON may contain null.

52 tools, always free

No watermarks, no account. Funded by non-intrusive display advertising only.

Frequently asked questions

Common questions about generating C# classes from JSON.

How do I convert JSON to a C# class?

Paste your JSON sample, set the root class name, choose your output style, and click Generate. The tool infers C# types from your JSON values and outputs a complete class definition ready to paste into Visual Studio, VS Code or Rider.

Should I use System.Text.Json or Newtonsoft.Json?

For new .NET 6/7/8/9 projects, use System.Text.Json — it's built-in, faster and Microsoft's recommended option. For legacy .NET Framework projects or projects already using Newtonsoft, stick with Newtonsoft.Json. Both are fully supported and produce identical JSON output for standard use cases.

How do I use the generated class in my ASP.NET Core project?

Copy the generated class into your Models folder. For System.Text.Json: var obj = JsonSerializer.Deserialize<Root>(jsonString). For Newtonsoft: var obj = JsonConvert.DeserializeObject<Root>(jsonString). In ASP.NET Core controllers, the framework deserializes [FromBody] parameters automatically.

What is the difference between a C# class and a C# record?

C# records (C# 9+) are immutable by default, have built-in value equality, and use a concise positional syntax. They're ideal for read-only API response models. Plain classes are mutable, use reference equality, and work with any .NET version. Both are deserialized identically by System.Text.Json and Newtonsoft.

Is the JSON to C# converter free?

Yes, completely free. No account required. JSONSwitcher is funded by non-intrusive display advertising.

Can Visual Studio convert JSON to C# classes?

Yes: Edit → Paste Special → Paste JSON As Classes. This converter gives you more control — records, System.Text.Json or Newtonsoft attributes and nullable reference types — and works without an IDE.

How are null values and large numbers typed in C#?

Keys whose sample value is null become nullable (object? or string?), and integers above int.MaxValue become long.
Go up