Skip to content

Instantly share code, notes, and snippets.

@battleguard
Created June 11, 2015 03:40
Show Gist options
  • Select an option

  • Save battleguard/835448a00bcb9bd9bcf2 to your computer and use it in GitHub Desktop.

Select an option

Save battleguard/835448a00bcb9bd9bcf2 to your computer and use it in GitHub Desktop.
private static void FormatJsonFile()
{
string jsonText = File.ReadAllText("Modules.json");
string goodText;
string[] textSplits = jsonText.Split('[', ']');
goodText = textSplits[0];
for (int i = 1; i < textSplits.Length; i+=2)
{
goodText += "[\r\n";
string textToFormat = textSplits[i];
string formattedText = textToFormat.Replace("\r", "").Replace("\n", "");
goodText += FormatCurlies(formattedText);
string textToAppent = "\t]" + textSplits[i + 1] ;
goodText += textToAppent;
}
File.WriteAllText("ModulesFormatted.json", goodText);
}
private static string FormatCurlies(string text)
{
string goodText = "";
string[] textSplits = text.Split('{', '}');
if (textSplits.Length == 1)
return text;
for(int i = 1; i < textSplits.Length; i+=2)
{
string maintext = textSplits[i];
string append = textSplits[i + 1];
goodText += "\t\t{" + maintext + "}" + append + "\r\n";
}
return goodText;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment