>_devtools

JSON to C# Class Converter

Generate C# classes from a JSON sample for System.Text.Json or Newtonsoft.Json, with namespace options.

What this does

Generates C# classes (POCOs) with auto-properties from a JSON sample, inside the namespace you choose. JSON keys are converted to PascalCase property names, and nested objects become separate partial classes.

Example

Input

{
  "id": 42,
  "name": "Ada",
  "verified": true,
  "tags": [
    "admin",
    "dev"
  ],
  "orders": [
    {
      "sku": "A1",
      "qty": 2
    },
    {
      "sku": "B2",
      "qty": 1,
      "note": "gift"
    }
  ]
}

Output with default options

namespace Example
{

    public partial class Root
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public bool Verified { get; set; }
        public string[] Tags { get; set; }
        public Order[] Orders { get; set; }
    }

    public partial class Order
    {
        public string Sku { get; set; }
        public long Qty { get; set; }
        public string? Note { get; set; }
    }
}

How values are mapped

  • Whole numbers become long, other numbers double (or decimal if you choose), strings string, booleans bool.
  • Arrays become T[] or List<T>, your choice.
  • Values that are sometimes null or missing become nullable (string?, long?).
  • ISO 8601 timestamps become DateTimeOffset and UUID strings become Guid when date detection is on.

Options

Pick System.Text.Json or Newtonsoft.Json. WithTypes only turned off the output adds the matching[JsonPropertyName] or [JsonProperty] attributes, plusFromJson and ToJson helpers and converters, so the original key names survive the PascalCase rename.

Things to know

System.Text.Json matches property names case-sensitively by default, so keep the attributes (turn Types only off) if your JSON uses camelCase keys and you have not configured a naming policy. A sample with several objects gives the best nullability.

Privacy

Generation runs in a Web Worker in your browser. The JSON is never uploaded.