Utilo

JSON to C# Converter – Free, Online, Private

Generate C# classes with JsonPropertyName attributes from a JSON sample so System.Text.Json can bind the payload.

Input
Output

How to convert JSON to C#

  1. Paste the JSON your API returns.
  2. Copy the classes. Integers are long, other numbers are double.
  3. Rename Root and add a namespace. Nullable annotations follow nulls seen in the sample.

Property style

Each object is a public class with auto-properties. Names are PascalCase to match C# convention, and a JsonPropertyName attribute repeats the JSON key so the binder does not depend on a naming policy. Integers become long, fractional numbers double, strings string, booleans bool. Lists use List<T>. Nested objects are separate classes in the same snippet. A property that was null, or missing on some merged objects, is annotated with ? so nullable reference types stay honest. Non-nullable strings are initialized to string.Empty and lists to new() so the class compiles without a constructor.

What System.Text.Json will do

With the attributes in place, JsonSerializer.Deserialize<Root>(json) fills the properties. A naming policy is unnecessary because the attribute is explicit. Fields the sample never showed are simply absent from the class; extra JSON keys are ignored by default. Case differences between Id and id are handled by the attribute, not by camelCase guessing. If you later enable PropertyNameCaseInsensitive you can drop some attributes, but the generated form does not assume that setting. Enums are not inferred. A status string stays string until you introduce an enum yourself.

Worked example

The small user sample becomes class Root with Id, Name, Active and Tags. Tags is List<string>. There is no nested address in this sample, so you only get one class. Add an address object and a second class appears. The using lines import System.Collections.Generic and System.Text.Json.Serialization. Paste the file into a console project that already targets a current .NET and the snippet compiles. Record types are not emitted; the sibling Java page uses records, this one uses classes because that is what most existing C# JSON samples still expect.

Limits

Date strings are not DateTime. Dictionary-shaped objects become classes with fixed properties, which is wrong for a map whose keys vary. Change the type to Dictionary<string, JsonElement> when that is the case. Integers larger than the safe JavaScript range are already rounded by JSON.parse before C# sees them. The generator runs locally, so a response copied from a production log is not posted to a code-generation server.

Frequently asked questions

Does it use Newtonsoft attributes?

No. Attributes are System.Text.Json.Serialization.JsonPropertyName. Newtonsoft would want JsonProperty instead.

Are properties nullable?

Only when the sample contained null or a merged object lacked the key. Other reference properties are initialized.

Can I get a record?

The snippet is a class. Changing class to record and the properties to init accessors is a small edit if you prefer that style.

Is the JSON uploaded?

No. The classes are built in the browser.