My json file looks like this
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Parameters": {
"Delay": 1000
}
}
I only want to change the "Delay" property. I can’t figure it out for the life of me. On YouTube they only show fairly linear examples and other goodies not related to my question. It’s a .net Core project and I’m not even sure whether I should install Newstonsoft.json (according to the mighty YouTube System.Text.Json is almost identical).
So if anyone could help me out, that would be great. I don’t even know what datastructure I am supposed to make for a structure like this. Again because the examples available mention the most simple structures only.
>Solution :
you need only several lines of code
using Newtonsoft.Json;
var path=@"C:\...";
var json = File.ReadAllText(path);
var jObj = JsonConvert.Parse(json);
jObj["Parameters"]["Delay"] = 2000;
json = jObj.ToString();
File.WriteAllText(path, json);