public void WriteAsJson(TextWriter output, string mode, ISerializationAnnotator annotator, bool pretty = false, int level = 0) { var jw = new JsonWriter(output, pretty: pretty, level: level); jw.OpenObject(); if (0 != Meta.Count) { jw.WriteProperty("meta", Meta); } if (null == Parent && null != Collectors && 0 != Collectors.Length) { jw.WriteProperty("collectors", Collectors.OfType <ICollector>().Select( c => new { key = c.Key, name = c.Name ?? c.Key, shortname = c.ShortName ?? c.Name ?? c.Key, group = c.Group, condition = c.Condition }.jsonify()).ToArray()); } if (null == Parent && null != Routs && 0 != Routs.Length) { jw.WriteProperty("routs", Routs.Select( c => new { key = c.Key ?? "nokey", name = c.Name ?? c.Key, shortname = c.ShortName ?? c.Name ?? c.Key, level = c.Level, parent = null == c.Parent ? "" : c.Parent.Key, }.jsonify()).ToArray()); } jw.WriteProperty("id", Id); jw.WriteProperty("isbucket", IsBucket); if (null != RouteKey) { jw.WriteProperty("key", RouteKey.Key); jw.WriteProperty("name", RouteKey.Name); jw.WriteProperty("sortkey", RouteKey.SortKey); jw.WriteProperty("comment", RouteKey.Comment); } jw.OpenProperty("values"); jw.OpenArray(); foreach (var value in Values) { jw.WriteObject(new { key = value.Key, value = value.Value }); } jw.CloseArray(); jw.CloseProperty(); if (null != _children && 0 != _children.Count) { jw.OpenProperty("aggs"); jw.OpenArray(); foreach (var node in Children) { jw.WriteObject(node.Value); } jw.CloseArray(); jw.CloseProperty(); } jw.CloseObject(); }