N
NJHTools

JSON to C# Class

Paste JSON and get C# classes with typed properties for every nested object, ready to deserialize in .NET. Free, no signup, and generated in your browser so nothing is uploaded.

Language

16 lines · processed in your browser, nothing is uploaded

C# output · Root.cs

Generated code appears here.

Example: JSON to C#

This JSON sample, with the root type named User, produces the C# below using the default options.

Input JSON
{
  "id": 1024,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "active": true,
  "score": 98.5,
  "tags": [
    "admin",
    "beta"
  ],
  "address": {
    "city": "London",
    "postcode": "NW1 6XE"
  }
}
Generated C#
namespace Example
{
    using System.Collections.Generic;

    public partial class User
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        public bool Active { get; set; }
        public double Score { get; set; }
        public List<string> Tags { get; set; }
        public Address Address { get; set; }
    }

    public partial class Address
    {
        public string City { get; set; }
        public string Postcode { get; set; }
    }
}

How to convert JSON to C#

  1. 1Paste a JSON object or array into the input.
  2. 2Select C# as the output language.
  3. 3Name the root class, for example Invoice.
  4. 4Adjust options such as namespace or serialization framework if available.
  5. 5Copy the classes into a .cs file in your project.

Mapping names with System.Text.Json

C# properties are PascalCase while JSON keys are often camelCase or snake_case. Put [JsonPropertyName("user_id")] on a property to bind it to an exact key, or set JsonSerializerOptions.PropertyNamingPolicy for a whole payload.

Deserialize with JsonSerializer.Deserialize<Invoice>(json, options). System.Text.Json is case-sensitive by default; set PropertyNameCaseInsensitive = true if the casing is inconsistent.

System.Text.Json or Newtonsoft.Json?

System.Text.Json ships with .NET and is the default in ASP.NET Core. Newtonsoft.Json uses [JsonProperty] instead of [JsonPropertyName] and is more lenient, which helps with older or irregular APIs.

The attributes differ between the two, so make sure the generated attributes match the library you actually reference.

Nullable types

With nullable reference types enabled, mark properties that can be missing or null as string? or Address?. Value types need the same treatment: int? and DateTime? for fields that may be absent.

Collections are usually best initialized to empty lists so callers do not need null checks.

Frequently Asked Questions

How do I convert JSON to a C# class?↓

Paste the JSON, choose C# and copy the generated classes. Each nested object becomes its own class with typed properties.

Which attribute maps a JSON key in System.Text.Json?↓

[JsonPropertyName("key")] from System.Text.Json.Serialization. Newtonsoft.Json uses [JsonProperty("key")] instead.

How are optional fields detected?↓

Types are inferred from the sample you paste. A field becomes optional only if it is missing from some of the objects, so paste an array with several representative records, or mark the field optional by hand after generating.

Does it handle nested arrays?↓

Yes. Arrays of objects become collections of a generated class, and nested arrays become nested collection or array types.

Is my JSON uploaded to a server?↓

No. The code generator (quicktype) runs entirely in your browser, so the JSON you paste never leaves your device. That makes it safe to use with internal API responses, though you should still strip secrets before sharing generated code.

Last updated: