JSON to C#

Generate C# classes from JSON with JsonPropertyName attributes, nullable types and List properties. Free and runs in your browser.

How to convert JSON to C#

  1. Paste a JSON object or array, for example a response from the API you are calling.
  2. Set the name of the root type.
  3. Copy the generated C# code into your project.

What you get

Tips for accurate results

The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.

Frequently asked questions

Is my JSON sent to a server?

No. The code is generated in your browser, so API responses and other private data never leave your device.

How do I deserialize the JSON?

Use JsonSerializer.Deserialize<Root>(json) from System.Text.Json. The JsonPropertyName attributes map each JSON key to its property, so no naming policy is needed.

Does it work with Newtonsoft.Json?

Replace [JsonPropertyName("x")] with [JsonProperty("x")] and the using with Newtonsoft.Json; the rest of the classes are the same.

Why do some properties have = "" or = new()?

With nullable reference types enabled (the default in modern .NET), non-nullable properties need a value so the compiler does not warn about possible nulls.