Suppose I have a JSON file that looks like the following:
[
{
"CheckName": "test2",
"Times": [
"0001-01-01T00:00:00",
"2019-02-27T09:29:39.5654213"
]
},
{
"CheckName": "test",
"Times": [
"0001-01-01T00:00:00",
"2019-02-27T09:29:39.574397"
]
}
]
Which I am looping over as below:
string Config = File.ReadAllText(@"C:\Scripts\Config.json");
dynamic ConfigFile = JsonConvert.DeserializeObject(Config);
foreach (var item in ConfigFile) {
string CurrentCheck = item.CheckName;
DateTime LastRun = item.Times[0];
DateTime NextRun = item.Times[1];
//Do stuff with the read values here
}
I need to update the first time value of test2, and then, later on, update it on test. However, there may be 50+ items in this JSON file, and I don't know where I am in the file, other than via a foreach loop (I'm reading the JSON, then looping over it to READ the values I need, but I need to write changes). Is it possible to update each specific value as I come across it, and then rewrite the JSON back to disk while retaining the other values as they are?
Alternatively, do I perhaps need to change how my JSON looks in order to make this task easier.
LastRunandNextRunare produce by the deserialisation.