---
title: "JSON to C# Class & Record Generator | JSON Lark"
description: "Generate C# classes or records from JSON samples, with System.Text.Json or Newtonsoft attributes and nullable reference types. Runs in your browser."
url: https://jsonlark.me/json-to-csharp/
---

Sheet 05 C# classes & records

# JSON to C#

Paste JSON samples and get C# classes or records with JsonPropertyName or JsonProperty attributes and nullable reference types.

## How it works

Properties are PascalCase and keep their JSON names in attributes, so the classes work with the default serializer settings. Keys missing from some objects and values that can be null become nullable.

- **Classes, records, positional records**: `{ get; set; }` properties, `{ get; init; }` records, or records with a primary constructor whose attributes use the `property:` target.
- **Nullable reference types**: Adds `#nullable enable` and `string?` where null is possible. Other reference properties get `= null!;`, or the `required` modifier when you tick "required members".
- **Attributes**: System.Text.Json matches property names case-sensitively, so leave attributes on unless you configure a naming policy. Newtonsoft ignores case either way.
- **Names**: A property named like its class gets a `Value` suffix, and names such as `Equals` are renamed so they do not hide object members.

## Questions

**How do I deserialize the result?**

With System.Text.Json: JsonSerializer.Deserialize<Root>(json). With Newtonsoft: JsonConvert.DeserializeObject<Root>(json). When the JSON's top level is an array, the output starts with a comment naming the list type to use.

**Why object for some properties?**

Values that mix kinds, such as a number in one sample and a string in another, have no single C# type. They become object (a JsonElement with System.Text.Json) so nothing fails to deserialize.

**Is my JSON uploaded?**

No. The code is generated by JavaScript running in this tab, and nothing you paste leaves it. The site counts page views with Cloudflare Web Analytics, which sets no cookies and never receives what you paste.
