title: How to update and add objects to a dynamically nested JSON?
body: <p>I have a class which contains a list of its instances of the same class. This can get pretty nested and is fairly dynamic. This class has other members and therefore you can have many different cases / setups with different type of nestings.</p>
  
  <p>I am trying to save it as JSON and deserialize when I need to access data.</p>
  
  <p>Serializing is easy since it successfully navigates through the nesting and generates the appropriate jsons. </p>
  
  <p>I am having trouble with updating. So when the session starts, I deserialize the json data that I have, I use this data when needed as a reference to load saved settings when certain elements are created.</p>
  
  <p>My problem is when I want to add a new entry to the json or make updates.</p>
  
  <p>To make updates, I can recursively loop through and find the item and make modifications it it but adding a new item is where I am having difficulty.</p>
  
  <p>Say a few nestings down the line, I have added a new item, How can I add this to the saved JSON in the appropriate spot?</p>
  
  <p>I would post my code but it spans several classes and I would need to post a lot of code. </p>
  
  <p>Essentially, I have a root class and then subclasses of the same type added as children to the list and other items.</p>
  
  <p>How do I determine where in the nestings the new item belongs?</p>
  
  <p>I can find specific items by recursively seraching every branch for its unique ID and make edits to that item to update it but not sure how to dynamically add a new item to specific places throughout the nesting.</p>
  
  <p>When first run, I just take the settings the user sets and store it as JSON.</p>
  
  <p>Next time, when it is run, I deserialize the data I have and store it.</p>
  
  <p>Based on what the user selects, I will load from the above step the settings for any item he selects.</p>
  
  <p>If the user adds a new item, somewhere through the nestings, I need to be able to determine where, then I need to combine both the old JSON and the new JSON (ovveride old values and add new elements if any) then serialize and write to file. </p>
  
  <p>I can't just serialize the new data and store it because then it would be missing the old data if it was not created in this session.</p>
  
  <p>It is kind of confusing but hopefully I have been helpful enough.</p>
  
  <p>Thanks</p>