While inserting new text into Json file its overwriting new text (insted of writing in new line). Here is my code
public static void WriteToJson()
{
string filepath = @"../../SchemaList.json";
// string filepath = @"C:\HoX_code\learning\Readjson\Readjson\SchemaList.json";
List<SchemaInfo> _oscheme = new List<SchemaInfo>();
_oscheme.Add(new SchemaInfo()
{
AuthenticateCmdlets= "AuthenticateCmdlets1",
GetPowerState= "GetPowerState1",
PowerOff= "PowerOff",
PowerOn= "PowerOn",
});
string json = JsonConvert.SerializeObject(_oscheme.ToArray(), Formatting.Indented);
using (StreamWriter sw = new StreamWriter(@"C:\HoX_code\learning\Readjson\Readjson\SchemaList.json"))
{
sw.Write(json);
}
/// File.WriteAllText(@"../../SchemaList.json", json);
}
Here i use File.WriteAllText & StreamWriter Both are working same