JSON to C# Class Converter
Turn a JSON sample into a C# class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.
What the JSON to C# generator does
Each object becomes a class with auto-properties and a JsonPropertyName attribute, which is what System.Text.Json reads. Property names are PascalCase while the attribute keeps the original spelling. A key that is absent from some array elements is typed with a question mark so a null deserialises; a key that was null in the sample is also nullable, and the field type says so rather than hiding it in a comment.
How to use it
JSON to C# Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the C# class below.
Worked example
Input:
{
"id": 42,
"displayName": "Ada Lovelace",
"active": true,
"score": 9.5,
"tags": [
"math",
"engine"
],
"address": {
"city": "London",
"country": "GB"
},
"projects": [
{
"name": "Analytical Engine",
"year": 1843
},
{
"name": "Note G",
"year": 1843,
"notes": "first published algorithm"
}
],
"nickname": null
}
Output:
// Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
// Rename and adjust to taste; the shape is inferred from one example, not a schema.
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Root
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("displayName")]
public string DisplayName { get; set; }
[JsonPropertyName("active")]
public bool Active { get; set; }
[JsonPropertyName("score")]
public double Score { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; }
[JsonPropertyName("address")]
public Address Address { get; set; }
[JsonPropertyName("projects")]
public List<Project> Projects { get; set; }
[JsonPropertyName("nickname")]
public object? Nickname { get; set; }
}
public class Address
{
[JsonPropertyName("city")]
public string City { get; set; }
[JsonPropertyName("country")]
public string Country { get; set; }
}
public class Project
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("year")]
public long Year { get; set; }
[JsonPropertyName("notes")]
public string? Notes { get; set; }
}
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns C# class; reloading the page discards both.
Each object becomes a class with auto-properties and a JsonPropertyName attribute, which is what System.Text.Json reads. Property names are PascalCase while the attribute keeps the original spelling. A key that is absent from some array elements is typed with a question mark so a null deserialises; a key that was null in the sample is also nullable, and the field type says so rather than hiding it in a comment.
Turn a JSON sample into a C# class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.
How to use it
JSON to C# Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the C# class below.
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns C# class; reloading the page discards both.
What to Expect
Best for
- Converting JSON to C# class when the data is already on screen.
What this tool keeps
- Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.
Sample input
{ "id": 42, "displayName": "Ada Lovelace", "active": true, "score": 9.5, "tags": [ "math", "engine" ], "address": { "city": "London", "country": "GB" }, "projects": [ { "name": "Analytical Engine", "year": 1843 }, { "name": "Note G", "year": 1843, "notes": "first published algorithm" } ], "nickname": null }
Sample output
// Generated from a JSON sample in the browser by AllTools — nothing was uploaded. // Rename and adjust to taste; the shape is inferred from one example, not a schema. using System.Collections.Generic; using System.Text.Json.Serialization; public class Root { [JsonPropertyName("id")] public long Id { get; set; } [JsonPropertyName("displayName")] public string DisplayName { get; set; } [JsonPropertyName("active")] public bool Active { get; set; } [JsonPropertyName("score")] public double Score { get; set; } [JsonPropertyName("tags")] public List<string> Tags { get; set; } [JsonPropertyName("address")] public Address Address { get; set; } [JsonPropertyName("projects")] public List<Project> Projects { get; set; } [JsonPropertyName("nickname")] public object? Nickname { get; set; } } public class Address { [JsonPropertyName("city")] public string City { get; set; } [JsonPropertyName("country")] public string Country { get; set; } } public class Project { [JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("year")] public long Year { get; set; } [JsonPropertyName("notes")] public string? Notes { get; set; } }
Frequently asked questions
How do I use the json to c# class converter?
JSON to C# Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the C# class below.
Is my input uploaded?
No. The text is parsed on this page with JavaScript and is never posted to a server.
Is there a size limit?
Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.