Skip to main content
DevDataKit
Open menu

Code generation

JSON to C# Class Generator

Generate clean C# classes from JSON, including nested objects, arrays, and nullable values.

Runs in your browser

This tool runs entirely in your browser. Nothing you paste or upload is sent to our servers.

Input

Characters: 0

Output

Characters: 0

Root type: —

Actions

Validation status:Ready

Settings

Invalid characters are converted into a valid C# class name.

Adds #nullable enable and nullable annotations for reference types.

How to use

  1. 1

    Add your JSON

    Paste a JSON object or array into the input editor, or load the sample. Everything stays in your browser.

  2. 2

    Configure the output

    Set the root class name, property naming, nullable reference types, collection style and serialization attributes.

  3. 3

    Generate C# classes

    Select Generate C#. The generator merges object shapes, handles nulls and missing fields, and avoids duplicate class names.

  4. 4

    Copy or download

    Copy the generated C# or download it as a .cs file, then add a namespace and adjust the serializer setup for your project.

Example

JSON

{
  "user": {
    "id": 1,
    "name": "Ada"
  }
}

Generated C#

// Generated by DevDataKit JSON to C# Class Generator.
// Root type: Root
#nullable enable
using System.Text.Json.Serialization;

public sealed class Root
{
    [JsonPropertyName("user")]
    public User User { get; set; } = null!;
}
public sealed class User
{
    [JsonPropertyName("id")]
    public int Id { get; set; }
    [JsonPropertyName("name")]
    public string Name { get; set; } = null!;
}

This small example shows how the JSON user object becomes a root class with a nested User class.

JSON to C# class generation guide

What JSON to C# conversion does

This tool parses a JSON document, infers the shape of its objects and arrays, and emits C# model classes. It is useful for creating DTOs for APIs, configuration payloads and integration tests without writing boilerplate by hand.

Generation is a static analysis of the JSON structure. It does not run or evaluate the input, and generated classes are a starting point for your project rather than a complete application layer.

How JSON properties map to C# properties

Each JSON property becomes a public C# property. PascalCase creates conventional C# names, while Original JSON names keeps the input spelling where it is a valid identifier.

Reserved keywords are escaped, invalid characters are sanitized, and naming collisions receive deterministic numeric suffixes. Serialization attributes preserve the original JSON name whenever the C# identifier differs.

Nullable properties

A property is nullable when it is explicitly null or missing from at least one object in an array. Value types use nullable forms such as int?, while reference types use string? or Class? when Nullable Reference Types is enabled.

With Nullable Reference Types on, the output includes #nullable enable and non-null reference initializers where appropriate. Turn the option off when your project uses the older nullable-disabled context.

Nested objects and collections

Nested objects become separate classes. Arrays of objects generate a class for the element shape, and arrays of primitives use List<T> or T[]. Nested arrays produce nested collection types.

When objects in an array have different properties, the shapes are merged and absent fields become nullable. Identical object shapes reuse one class, and class-name collisions receive a safe numeric suffix.

System.Text.Json vs Newtonsoft.Json

System.Text.Json uses JsonPropertyName attributes from System.Text.Json.Serialization. Newtonsoft.Json uses JsonProperty attributes from the Newtonsoft.Json namespace.

Choose the serializer already used by your application. The generated using directive and attributes match the selection; attributes are only added when the C# name would otherwise differ from the JSON name.

Common use cases

The generator is useful when integrating with a new API, creating typed request and response models, exploring a JSON payload, building configuration classes, or producing quick DTOs for a .NET application.

Review generated code before production use: add a namespace, configure your serializer, decide whether to use records or classes, and check how your application represents dates, decimals and unknown values.

FAQ

Is the generated C# code ready to compile?

The generator emits standard C# classes and attributes. Representative outputs are compiled with the .NET SDK during development. You still need to add an appropriate namespace, project target and serializer package/settings for your application.

How are JSON property names mapped to C# properties?

PascalCase converts names such as user_name to UserName. Original JSON names preserves valid names. When the generated identifier differs from the JSON name, a JsonPropertyName or JsonProperty attribute preserves the original name.

What happens to nullable and missing properties?

A property is nullable when its value is null or when it is missing from some objects in an array. Nullable value types use ?, and nullable reference types use ? when Nullable Reference Types is enabled. The option also controls the #nullable directive and non-null initializers.

How are nested objects and arrays handled?

Nested objects become separate classes. Arrays of objects generate an element class; primitive arrays use List<T> or T[], and nested arrays become nested collections. Object shapes in an array are merged so fields from every object are retained.

What about heterogeneous arrays?

Arrays containing different object shapes are merged into one class with nullable properties. Arrays mixing objects and primitive values use object, because a single strongly typed element cannot represent both without discarding data.

Which serialization attributes should I choose?

Choose System.Text.Json when your project uses System.Text.Json, or Newtonsoft.Json when it uses Newtonsoft. The generated attributes and using directive match the selected option. Attributes are only emitted where needed.

Is my JSON uploaded to a server?

No. JSON parsing, type inference, C# generation, copying and downloading all happen locally in your browser.

Can I convert a top-level JSON array?

Yes. For a top-level array of objects, the root class represents the array element and the displayed root type is the collection type. For primitive roots, no model classes are required.

Available

Data & JSON

JSON Formatter

Beautify, minify, validate, and sort JSON with clear, line-aware error reporting.

Runs in your browserOpen tool
Available

Date & time

Timestamp Converter

Convert Unix timestamps to dates and dates to timestamps across UTC and selected time zones.

Runs in your browserOpen tool