public string ToJson() { JsonData root = new JsonData(); foreach (KeyValuePair <AssetType, Dictionary <string, object> > keyValuePair in data) { if (keyValuePair.Value.Count == 0) { continue; } JsonData assetRoot = new JsonData(); AssetType assetType = keyValuePair.Key; root[assetType.ToString()] = assetRoot; foreach (KeyValuePair <string, object> assetsPair in keyValuePair.Value) { Type type = Type.GetType(assetType.GetType().Namespace + "." + assetType + "Config"); JsonData assetData = JsonMapper.ToObject(JsonMapper.ToJson(assetsPair.Value)); assetRoot[assetsPair.Key] = assetData; } } return(JsonMapper.ToJson(root, true)); }