using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
""AlphabeticName"": ""Better^Make^U.^MD""
var dict = JsonConvert.DeserializeObject<Dictionary<string, Node>>(json, new NodeConverter());
private static void Dump(Dictionary<string, Node> dict, string indent)
foreach (var kvp in dict)
Console.WriteLine(indent + kvp.Key + " (" + node.vr + "):");
foreach (Dictionary<string, Node> d in node.Value)
else if (node.vr == "PN")
foreach (PnItem item in node.Value)
Console.WriteLine(indent + " " + item.AlphabeticName);
else if (node.vr != null)
foreach (object obj in node.Value)
Console.WriteLine(indent + " " + (obj != null ? obj.ToString() : "(null)"));
public IList Value { get; set; }
public string vr { get; set; }
public string AlphabeticName { get; set; }
class NodeConverter : JsonConverter
public override bool CanConvert(Type objectType)
return (objectType == typeof(Node));
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JObject jo = JObject.Load(reader);
node.vr = (string)jo["vr"];
node.Value = jo["Value"].ToObject<List<PnItem>>(serializer);
else if (node.vr == "SQ")
node.Value = jo["Value"].ToObject<List<Dictionary<string, Node>>>(serializer);
node.Value = jo["Value"].ToObject<List<string>>(serializer);
public override bool CanWrite
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();