public string ToJson()
        {
            var config = this.Virtualize(this.ControllerName);

            Complete();
            var ruleIterator      = config.Select("/c:dataController/c:businessRules/c:rule");
            var newOnServer       = false;
            var calculateOnServer = false;

            while (ruleIterator.MoveNext())
            {
                var type        = ruleIterator.Current.GetAttribute("type", string.Empty);
                var commandName = ruleIterator.Current.GetAttribute("commandName", string.Empty);
                if (type != "JavaScript")
                {
                    if ((commandName == "New") && !newOnServer)
                    {
                        newOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(string.Empty, "newOnServer", null, "true");
                    }
                    else
                    if ((commandName == "Calculate") && !calculateOnServer)
                    {
                        calculateOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(string.Empty, "calculateOnServer", null, "true");
                    }
                }
            }
            var expressions = JArray.FromObject(this.Expressions).ToString();
            var exceptions  = new string[] {
                "//comment()",
                "c:dataController/c:commands",
                "c:dataController/@handler",
                "//c:field/c:formula",
                "//c:businessRules/c:rule[@type=\"Code\" or @type=\"Sql\" or @type=\"Email\"]",
                "//c:businessRules/c:rule/text()",
                "//c:validate",
                "//c:styles",
                "//c:visibility",
                "//c:readOnly",
                "//c:expression",
                "//c:blobAdapterConfig"
            };

            foreach (var ex in exceptions)
            {
                var toDelete = new List <XPathNavigator>();
                var iterator = config.Select(ex);
                while (iterator.MoveNext())
                {
                    toDelete.Add(iterator.Current.Clone());
                }
                foreach (var node in toDelete)
                {
                    node.DeleteSelf();
                }
            }
            // special case of items/item serialization
            var itemsIterator = config.Select("//c:items[c:item]");

            while (itemsIterator.MoveNext())
            {
                var lovBuilder   = new StringBuilder("<list>");
                var itemIterator = itemsIterator.Current.SelectChildren(XPathNodeType.Element);
                while (itemIterator.MoveNext())
                {
                    lovBuilder.Append(itemIterator.Current.OuterXml);
                }
                lovBuilder.Append("</list>");
                itemsIterator.Current.InnerXml = lovBuilder.ToString();
            }
            // load custom view layouts
            var viewIterator = config.Select("//c:views/c:view");

            while (viewIterator.MoveNext())
            {
                var layout = LoadLayout(viewIterator.Current.GetAttribute("id", string.Empty));
                if (!(string.IsNullOrEmpty(layout)))
                {
                    viewIterator.Current.AppendChild(string.Format("<layout><![CDATA[{0}]]></layout>", layout));
                }
            }
            // extend JSON with "expressions"
            var json = XmlConverter.ToJson(config.Navigator, "dataController", true, true, "commands", "output", "fields", "views", "categories", "dataFields", "actions", "actionGroup", "businessRules", "list");
            var eof  = Regex.Match(json, "\\}\\s*\\}\\s*$");

            json = (json.Substring(0, eof.Index)
                    + (",\"expressions\":"
                       + (expressions + eof.Value)));
            return(json);
        }
        public static string ToJson(XPathNavigator navigator, string root, bool metadata, bool explicitElementValues, params System.String[] arrays)
        {
            var xmlc = new XmlConverter(navigator, root, metadata, explicitElementValues, arrays);

            return(xmlc.ToJson());
        }
        public static string ToJson(XPathNavigator navigator, string root, bool metadata, params System.String[] arrays)
        {
            XmlConverter xmlc = new XmlConverter(navigator, root, metadata, arrays);

            return(xmlc.ToJson());
        }