ToolFeather
Developer / SEORuns in your browser

JSON to C# Class Generator

Paste JSON and get C# classes for System.Text.Json: PascalCase properties with [JsonPropertyName] attributes, List<T> for arrays, nested classes, and nullable types where values can be missing.

Quick presets

JSON to C# Class

JSON
C#

Runs in your browser — nothing you enter is uploaded or stored.

ToolFeather · JSON → C#
Scratchpad auto-saved
Stored in this browser (localStorage)
Step-by-step~40s read

How it works — in four simple steps

No signup and nothing to install — it all runs in your browser.

1

Add your JSON

Paste it into the left box, press Open file, or drag a .json file onto it. Sample loads a realistic example.

2

Set the options

Adjust the options above the boxes — the output updates instantly as you change them.

3

Check the result

Read the status line: it reports rows, keys and any value that couldn't be represented in C#.

4

Copy or download

Copy the C# or download it as a .cs file. Nothing was uploaded at any point.

Pro tip

Use decimal instead of double for money fields before shipping.

Features

Named types

Choose the root type name; nested objects become their own named types, and identical shapes are merged.

System.Text.Json attributes

[JsonPropertyName] on every property, nullable types for optional values and a file-scoped namespace.

Private by design

Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.

About the JSON to C# Class

In .NET, JSON is usually deserialised into plain classes (POCOs). This generator creates them from a sample: each object becomes a public class, each key a { get; set; } property named in PascalCase, and a [JsonPropertyName("original_key")] attribute keeps the mapping exact — so JsonSerializer.Deserialize<Root>(json) works without a naming policy.

Types are inferred across all elements: whole numbers become long, decimals double, booleans bool, strings string, arrays List<T>, nested objects their own class. Keys missing from some objects or null in some become nullable (long?, string?), which lines up with nullable reference types. Non-nullable strings, lists and nested objects are initialised (= string.Empty;, = new();) so the code compiles cleanly with <Nullable>enable</Nullable>.

The output uses a file-scoped namespace (C# 10 / .NET 6 and later). Identical shapes share one class.

Examples

A weather API response with snake_case keys, a nested location, a list of hourly readings and a nullable field.

JSON input
{
  "location": { "name": "Pune", "lat": 18.52, "lon": 73.86 },
  "generated_at": "2026-10-21T06:00:00Z",
  "hourly": [
    { "time": "2026-10-21T07:00:00Z", "temp_c": 22.4, "rain_mm": 0, "alert": null },
    { "time": "2026-10-21T08:00:00Z", "temp_c": 24.1, "rain_mm": 0.2, "alert": "Light rain" }
  ]
}
C# output
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Weather.Api;

public class Forecast
{
    [JsonPropertyName("location")]
    public Location Location { get; set; } = new();

    [JsonPropertyName("generated_at")]
    public string GeneratedAt { get; set; } = string.Empty;

    [JsonPropertyName("hourly")]
    public List<HourlyItem> Hourly { get; set; } = new();
}

public class Location
{
    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    [JsonPropertyName("lat")]
    public double Lat { get; set; }

    [JsonPropertyName("lon")]
    public double Lon { get; set; }
}

public class HourlyItem
{
    [JsonPropertyName("time")]
    public string Time { get; set; } = string.Empty;

    [JsonPropertyName("temp_c")]
    public double TempC { get; set; }

    [JsonPropertyName("rain_mm")]
    public double RainMm { get; set; }

    [JsonPropertyName("alert")]
    public string? Alert { get; set; }
}

This output was produced by the converter on this page with root Forecast in namespace Weather.Api — load it with the “Weather API” preset above and change any option to see the effect.

How JSON maps to C#

In JSONBecomes in C#
"user_id": 7[JsonPropertyName("user_id")] public long UserId { get; set; }
9.5double
["a"]List<string> = new();
Nested objectits own class, initialised with = new();
Missing or null somewherenullable type, e.g. string?
Mixed typesobject?

Things that trip people up

JSON vs C# at a glance

PropertyJSONC#
SpecificationRFC 8259 (2017) · ECMA-404System.Text.Json (.NET 6+)
File extension.json.cs
Media typeapplication/jsontext/plain
Data typesstring, number, boolean, null, object, arraystring, long, double, bool, List<T>
CommentsNoYes
NestingUnlimitedNamed classes

Frequently asked questions

5 answers
How do I convert JSON to a C# class?
Paste the JSON, set a namespace, and copy the classes into a .cs file. Deserialize with JsonSerializer.Deserialize(json).
Does it work with Newtonsoft.Json?
The classes do; swap [JsonPropertyName] for [JsonProperty] and the using directive to Newtonsoft.Json.
Why are some properties nullable?
Because the value was null or missing in at least one sample object. That keeps deserialisation honest under nullable reference types.
Which .NET version is required?
.NET 6 or later for the file-scoped namespace; remove the namespace line's semicolon form and use braces for older versions.
Is my data uploaded anywhere?
No. The JSON is parsed and converted by JavaScript in your browser tab; nothing is sent to a server, so it is safe for internal exports, customer lists and configuration files with secrets.