I'm using a json file as a data source in a small app written in C#. I spent last evening looking after the best ways to do CRUD actions with a json data source and the one thing bugging me is that it doesn't seem possible to add/modify data without serializing the whole file to my class, adding an item to the list/updating an item then rewrite the whole thing to the file.
Something like that, which I'd like to avoid if possible :
var allUsers = jData.ToObject<List<JsonEntry>>();
allUsers.Add(newEntry);
var convertedItems = JsonConvert.SerializeObject(allUsers, Formatting.Indented);
File.WriteAllText("UsersConfiguration.json", convertedItems);
Any idea on how to handle writing/updating in a better way ?
Thanks in advance !
JsonTextReaderandJsonTextWriterofNewtonSoft2) Serialzie toJObjectand update the value anddeserializeback to Json string to write to file.