JSONGenerator
GeneratorSchemaConvertersExamplesDocs

JSONGenerator

Free online tools for generating random JSON data and JSON Schemas.

Quick Links

  • JSON Generator
  • JSON Schema Converter
  • Examples
  • Docs
  • Blog
  • About
  • Contact
  • Privacy Policy

Converters

  • JSON to YAML
  • YAML to JSON
  • XML to JSON
  • JSON to XML
  • JSON to TOML
  • TOML to JSON
  • JSON to CSV
  • CSV to JSON
  • JSON to Excel
  • Excel to JSON
  • JSON to HTML table
  • JSON to TypeScript
  • JSON to C#
  • JSON to Go
  • JSON to Java
  • JSON to SQL

Support

Having issues? Contact us.

© 2026 JSON Generator. All rights reserved.

JSON to C# Class Converter

Paste JSON and get C# classes with typed properties and serializer attributes as you type.

JSON Input

Paste JSON, upload a .json file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "order_id": 100234,
  "customer": {
    "first_name": "Ada",
    "last_name": "Lovelace",
    "email": "ada@example.com",
    "phone": null
  },
  "total": 59.9,
  "paid": true,
  "created_at": "2025-03-14T09:30:00Z",
  "tags": ["priority", "gift"],
  "items": [
    { "sku": "KB-01", "quantity": 2, "unit-price": 24.95 },
    { "sku": "MS-07", "quantity": 1, "unit-price": 10, "note": "Fragile" }
  ]
}

C# Output

Updates as you type. Copy it or download a Models.cs file.

1

Converting…

Convert JSON to C# classes online

This free JSON to C# class converter reads a sample JSON document and writes the C# classes that describe it. Paste an API response, a config file or a webhook payload, and you get a ready-to-use Root class plus a separate class for every nested object, with typed properties you can drop straight into your project. Nothing is installed or uploaded: the classes are generated in your browser.

It saves the tedious part of calling a JSON API from .NET. Instead of typing out dozens of properties and guessing their types, you paste the response once and deserialize it into a strongly typed object with a single line of code. The output is plain C# with no helper code, so it works in ASP.NET Core, console apps, Blazor and .NET MAUI alike.

How to convert JSON to a C# class

  1. Paste your JSON into the JSON Input editor, or upload a .json file or drag one onto the editor.
  2. Set the Class name for the root object (the default is Root) and the Namespace you want the classes to live in.
  3. Pick the Serializer your project uses: System.Text.Json or Newtonsoft.Json. The attributes on each property change to match.
  4. Read the C# Output. If the JSON is invalid, the status bar shows the parser error. Then click Copy, or Download to save a Models.cs file.

JSON to C# class example

Here is a small order document and the classes the converter produces from it with the default options. Snake_case keys become PascalCase properties, each nested object gets its own class, the array becomes a List<Item>, and the ISO timestamp becomes a DateTimeOffset.

JSON input
{
  "id": 1042,
  "order_number": "A-1042",
  "total": 59.9,
  "created_at": "2025-03-14T09:30:00Z",
  "customer": {
    "first_name": "Ada",
    "phone": null
  },
  "items": [
    { "sku": "KB-01", "quantity": 2 },
    { "sku": "MS-07", "quantity": 1, "note": "Fragile" }
  ]
}
C# output
namespace MyApp.Models
{
    using System;
    using System.Collections.Generic;

    using System.Text.Json;
    using System.Text.Json.Serialization;
    using System.Globalization;

    public partial class Root
    {
        [JsonPropertyName("id")]
        public long Id { get; set; }

        [JsonPropertyName("order_number")]
        public string OrderNumber { get; set; }

        [JsonPropertyName("total")]
        public double Total { get; set; }

        [JsonPropertyName("created_at")]
        public DateTimeOffset CreatedAt { get; set; }

        [JsonPropertyName("customer")]
        public Customer Customer { get; set; }

        [JsonPropertyName("items")]
        public List<Item> Items { get; set; }
    }

    public partial class Customer
    {
        [JsonPropertyName("first_name")]
        public string FirstName { get; set; }

        [JsonPropertyName("phone")]
        public object Phone { get; set; }
    }

    public partial class Item
    {
        [JsonPropertyName("sku")]
        public string Sku { get; set; }

        [JsonPropertyName("quantity")]
        public long Quantity { get; set; }

        [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
        [JsonPropertyName("note")]
        public string? Note { get; set; }
    }
}

How JSON maps to C# types

JSON values and the C# types generated for them
JSONC# typeNotes
stringstringStrings that look like ISO 8601 dates or date-times become DateTimeOffset.
whole numberlongHolds any integer an API is likely to return. Change it to int by hand if you know it stays small.
decimal numberdoubleAn array that mixes whole and decimal numbers becomes List<double>.
true / falseboolAlways a plain bool.
nullobjectA value that is only ever null gives the converter nothing to infer a type from.
{ } objectA new classNamed after the property that holds it. The root uses the class name option.
[ ] arrayList<T>T is the element type, or a class for an array of objects.

Property names and attributes

C# properties are PascalCase by convention, while JSON keys are usually camelCase or snake_case. The converter renames each property to PascalCase (first_name becomes FirstName, order-id becomes OrderId) and adds an attribute holding the exact JSON key: [JsonPropertyName("first_name")] for System.Text.Json or [JsonProperty("first_name")] for Newtonsoft.Json. That matters because System.Text.Json matches property names case-sensitively by default, so a PascalCase property would otherwise stay empty.

Keys that are not valid C# identifiers are cleaned up the same way. A key such as 2fa becomes The2Fa, and the attribute still points at the original key. On .NET 8 and later you can skip the attributes and set PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower instead, if all your keys use snake_case.

Nullable types and nullable reference types

The converter looks at every object in an array. A property that is missing or null in some items but present in others becomes nullable: string?, long? and so on. The note property in the example above works this way. With System.Text.Json these properties also get JsonIgnoreCondition.WhenWritingNull, so they are left out when you serialize a null.

Properties that were always present are not marked as nullable. If your project enables <Nullable>enable</Nullable>, the compiler warns (CS8618) that those properties are uninitialized when the class is constructed. Add the required modifier on C# 11 and later, give them a default such as = string.Empty;, or add ? where the API may omit the value.

Dates, numbers and mixed arrays

The converter only sees the sample you paste, so it infers types from that one document. A decimal written as 1.0 is read as the whole number 1 by the JSON parser and therefore becomes long; use a value such as 1.5 in your sample if the field is really a decimal. Date-only strings like 2025-03-14 also become DateTimeOffset; change the type to DateOnly if you prefer. An array that mixes types, such as [1, "a"], produces a helper struct for the union, which is rarely what you want, so it is usually better to fix the data.

Deserializing JSON into the classes

Once the classes are in your project, a single call turns JSON text into a C# object. If the JSON document is an array, deserialize to List<Root> instead of Root.

System.Text.Json
using System.Text.Json;
using MyApp.Models;

string json = File.ReadAllText("order.json");
Root? order = JsonSerializer.Deserialize<Root>(json);

Console.WriteLine(order?.Customer.FirstName); // Ada

// Back to JSON; "note" is left out when it is null
string output = JsonSerializer.Serialize(order);
Newtonsoft.Json
using Newtonsoft.Json;
using MyApp.Models;

string json = File.ReadAllText("order.json");
Root? order = JsonConvert.DeserializeObject<Root>(json);

Console.WriteLine(order?.Customer.FirstName); // Ada

string output = JsonConvert.SerializeObject(order);

Compared with Visual Studio's Paste JSON as Classes

Visual Studio has the same idea built in: copy JSON, open a .cs file and choose Edit > Paste Special > Paste JSON as Classes. It is convenient inside the IDE, but it keeps the JSON keys as property names, so snake_case ends up in your C# code, and it offers no options for the root class name, namespace or serializer. This online tool works in any browser, on any machine, and produces idiomatic names with attributes that keep the mapping intact.

Why convert JSON to a C# object?

  • Calling REST APIs: Model a third-party response once and read it with IntelliSense and compile-time checks instead of string keys.
  • ASP.NET Core request and response models: Start a controller or minimal API DTO from a real payload, then trim it to the fields you need.
  • Webhooks and message queues: Turn a sample event from a payment provider or a queue message into a class you can deserialize safely.
  • Config files and test fixtures: Bind appsettings-style JSON to a typed class, or load fixture files in unit tests as real objects.

Working in another language? The same approach is available as a JSON to TypeScript converter, a JSON to Java converter and a JSON to Go converter. Need a realistic payload to test with? Create one with the JSON Generator, and if you would rather validate documents than generate classes, build a contract with the JSON Schema generator.

Frequently Asked Questions

How do I convert JSON to a C# class?

Paste your JSON into the JSON Input editor, or upload a .json file. The C# classes appear in the output editor as you type. Set the class name, namespace and serializer, then copy the code or download it as Models.cs.

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

Choose the library your project already uses. System.Text.Json ships with modern .NET and gets [JsonPropertyName] attributes; Newtonsoft.Json is a NuGet package and gets [JsonProperty] attributes. The classes are otherwise identical.

How do I deserialize JSON into the generated classes?

With System.Text.Json call JsonSerializer.Deserialize<Root>(json). With Newtonsoft.Json call JsonConvert.DeserializeObject<Root>(json). Replace Root with the class name you chose, or use List<Root> when the JSON is an array.

Why does the converter use long instead of int?

A sample can't tell the converter how large a number may get, and a JSON integer can exceed the range of int. long holds any whole number a typical API returns, and you can change a property to int by hand when you know the range is small.

Why is a null value generated as object, and what makes a property nullable?

A property that is only ever null in your sample has no type to infer, so it becomes object. If the same property has a value in one array item and is null or missing in another, it becomes a nullable type such as string? or long?.

How is this different from Visual Studio's Paste JSON as Classes?

Paste JSON as Classes needs Visual Studio and keeps the JSON names as C# property names. This converter works in any browser, gives you PascalCase properties, and adds attributes so they still map to the original JSON names.

Is my JSON uploaded to a server?

No. The classes are generated entirely in your browser, so your JSON never leaves your device. It is safe to use with real API responses and internal payloads.

Related converters

  • JSON to TypeScript ConverterGenerate TypeScript interfaces or types from a JSON sample.
  • JSON to Go Struct ConverterGenerate Go structs with json tags from a JSON sample.
  • JSON to Java Class ConverterGenerate Java POJO classes with getters and setters from JSON.
  • JSON to SQL ConverterGenerate a CREATE TABLE statement and INSERT rows from a JSON array.
  • JSON to YAML ConverterConvert JSON to clean, readable YAML for config files, Kubernetes and CI pipelines.
  • YAML to JSON ConverterConvert YAML, including anchors and multi-document files, to formatted JSON.

See all JSON converters