Appending new data to an existing JSON file Appending new data to an existing JSON file json json

Appending new data to an existing JSON file


You can try to deserialize the data in to a object Expence and add your data, then serialize the object (list of objects) to file.


Since you can read directly into an Expense object, you should be able to add such an object to a List<Expense> - add the new data as an Expense object to the list (directly from your form data, or otherwise).

At this point you should be able to write out the List<Expense> out using JSON.NET - it should take care of creating the list.

I suggest you always save a List<Expense>, even if it contains only one item as it would make serializing and deserializing easier.