using System.Collections.Generic;
public static void Main(string[] args)
""text"": ""Gift amount"",
""widget_type"": ""HEADER""
""hint"": ""Original text: Name""
""placeholder_last_name"": ""Last name"",
""placeholder_first_name"": ""First name"",
""widget_type"": ""NAME""
""hint"": ""Original text: Email""
""widget_type"": ""EMAIL""
var arrayInParent = @"{""name"": ""root"", ""children"": " + simpleArray + "}";
var deserializeArray = JsonConvert.DeserializeObject<Widget[]>(simpleArray);
foreach (var widget in deserializeArray)
Console.WriteLine(widget.GetType());
Console.WriteLine("------");
var deserializeInParent = JsonConvert.DeserializeObject<Root>(arrayInParent);
foreach (var widget in deserializeInParent.Children)
Console.WriteLine(widget.GetType());
[JsonProperty("name", Required = Required.Always)]
public string WidgetType { get; set; }
[JsonConverter(typeof(JsonSubtypes), "widget_type")]
[JsonProperty("children", Required = Required.Always)]
public List<Widget> Children { get; set; }
[JsonConverter(typeof(JsonSubtypes), "widget_type")]
[JsonSubtypes.KnownSubType(typeof(HeaderWidget), "HEADER")]
[JsonSubtypes.KnownSubType(typeof(NameWidget), "NAME")]
[JsonSubtypes.KnownSubType(typeof(EmailWidget), "EMAIL")]
public abstract class Widget
[JsonProperty("order", Required = Required.Always)]
public int Order { get; set; }
[JsonProperty("widget_type", Required = Required.Always)]
public string WidgetType { get; set; }
public class HeaderWidget : Widget
public const string WIDGET_TYPE = "HEADER";
WidgetType = WIDGET_TYPE;
[JsonProperty("text", Required = Required.Always)]
public string Text { get; set; }
public class NameWidget : Widget
public const string WIDGET_TYPE = "NAME";
WidgetType = WIDGET_TYPE;
[JsonProperty("label", Required = Required.Always)]
public Label Label { get; set; }
[JsonProperty("placeholder_last_name", Required = Required.Always)]
public string PlaceholderLastName { get; set; }
[JsonProperty("placeholder_first_name", Required = Required.Always)]
public string PlaceholderFirstName { get; set; }
public class EmailWidget : Widget
public const string WIDGET_TYPE = "EMAIL";
WidgetType = WIDGET_TYPE;
[JsonProperty("label")] public Label Label { get; set; }
[JsonProperty("required")] public bool EmailWidgetRequired { get; set; }
[JsonProperty("text", Required = Required.Always)]
public string Text { get; set; }
[JsonProperty("hint", Required = Required.Always)]
public string Hint { get; set; }