JSON to C# Class

Turn a sample JSON object into C# classes with one property for each key. Nested objects become their own classes, and arrays become List types.

1 Paste your text and pick the options

2 Your answer

Your answer shows here as you type.

How to use the JSON to C# Class

  1. Paste a sample JSON object or an array of objects into the box.
  2. Set the name of the root class, such as Order or User.
  3. Choose get; set; or get; init; for the property style.
  4. Copy the generated C# classes into your project.

Frequently asked questions

How are JSON value types mapped to C# types?

true and false become bool, whole numbers become int (or long if they are too large for int), decimal numbers become double, text becomes string, and null becomes object.

What does JsonPropertyName do?

It tells System.Text.Json which JSON key a C# property maps to. It is added when the C# property name differs from the JSON key, such as first_name becoming FirstName.

When should I use get; init; instead of get; set;?

init lets a value be set when the object is created, such as through a constructor or object initializer, and then keeps it read-only. It suits data that is not changed after it is loaded.

Wrote something with AI? Slop Monkey rewrites it so it sounds like you, and keeps your facts.