When writing a json string to a file using the following code below, it doesn't show up in a pretty format when editing the file, but rather just shows up as a string format. If I use .Net fiddle, the console output is correct and it looks good. How do I write the json string to a file, so when editing /w say notepad++ it shows up in a pretty format. Can someone help?
.Net Fiddle code for console output which works fine
public class Program
{
public static void Main()
{
String sPrettyStr;
var item = "{\"messageType\":\"0\",\"code\":\"1\"}";
sPrettyStr = JValue.Parse(item).ToString(Newtonsoft.Json.Formatting.Indented);
Console.WriteLine(sPrettyStr);
}
}
.Net Fiddle console output
{
"messageType": "0",
"code": "1"
}
But when writing a formatted json string to file using this
File.WriteAllText(c:/test.json,JValue.Parse(item).ToString(Newtonsoft.Json.Formatting.Indented))
I get this file output when edited w/ notepad++
"{\\\"messageType\\\":\\\"0\\\",\\\"code\\\"}"