How to use the JSON to C# converter

  1. Paste a JSON sample, such as an API response, or select Load example.
  2. Set the root class name and, optionally, a namespace.
  3. Choose your serializer and style options. The C# updates as you type.
  4. Copy the code or download it as a .cs file.

How types are chosen

Types come from every value in your sample, not just the first one, so a richer sample gives more precise types:

  • Numbers become int when every value fits, then long, and decimal beyond that. Numbers with a fractional part become double, or decimal if you choose it (recommended for money).
  • Strings become Guid, DateOnly, DateTime or DateTimeOffset when every value has that format, and string otherwise.
  • Arrays of objects are merged into one class. A property that's missing from some items, or is ever null, becomes nullable.
  • Objects keyed by IDs, such as {"101": {...}, "102": {...}}, become Dictionary<string, T>.
  • Identical shapes share one class, and class names come from property names, made singular for array items (items → Item).

Values that are only ever null, empty arrays, and arrays that mix different types become object. The converter tells you when this happens, so you can add a better sample or choose the type yourself.

Nullable reference types and required members

With nullable reference types on, the generated code compiles without warnings: non-nullable strings, collections and objects get initializers (string.Empty, [] and new()). If you prefer, select required members instead. System.Text.Json (.NET 8 and later) then rejects JSON that's missing those properties.

The output uses current C# features (file-scoped namespaces and collection expressions), so it needs C# 12 / .NET 8 or later.

System.Text.Json or Newtonsoft.Json?

Choose System.Text.Json for new .NET projects; it's built in. The converter adds [JsonPropertyName] attributes so properties map to the JSON names exactly, because System.Text.Json is case-sensitive by default. Choose Newtonsoft.Json for projects that already use it; the converter adds [JsonProperty] instead. With None, no attributes are added and names only map if your serializer settings match them, for example JsonSerializerDefaults.Web for camelCase JSON.

Frequently asked questions

Is my JSON uploaded?

No. The conversion runs entirely in your browser; nothing is sent to our servers or logged.

Is the generated code tested?

Yes. Our test suite compiles the converter's output for a range of samples and options with the C# compiler, requiring zero errors and zero warnings. It also deserializes the original JSON into the generated classes with both System.Text.Json and Newtonsoft.Json and checks the values.

Can I deserialize a JSON array?

Yes. If your JSON is an array of objects, the converter generates the item class and reminds you to deserialize it as List<Root>.