title: Handle dicts/json with nested elements
body: <p><strong>tldr;</strong> Python 3.8. I want to work with a ‘clean’ dict with no empty entries to generate an adequate json output. For this case I need a function which handles it and supported a nested structure. This solution should be generic enough to work with n nested objects.</p>
  
  <p>I want to work with a ‘clean’ dict with no empty entries to generate an adequate json output in Python 3.8. Internally I use a dict to store everything which will later dump to the disk. I know that <code>{}</code> is a valid json (and <code>{“data”:{}}</code> also) but IMHO it’s not clean. Parsing this kind of json only shows that nothing useful is stored.</p>
  
  <p>So the idea is to avoid this unclean json by checking key/values which are added or removed to the json. This should support nested values to, like <code>{"os":{"network":{"ip":"”localhost”"}}}</code> (any depth), usable in an OOP style, e.g. <code>def handleElement(key,value,**sections)</code>. If the value is empty, it should ‘clean up’ the dict removing every section if the section has no content. </p>
  
  <p>After hours of searching I found neither a python build-in way to do this or some extensions or solutions on the web. I tried a lot by myself, but I found no way to iterate smooth over the dict and work on it. Because the calling syntax for dicts with nested elements is <code>dict[][][]…</code> I found no way to iterate over the dict and call the nested elements without coding every depth by hand. </p>
  
  <p>Do you have any good idea? If you need more information or something is unclear, please ask!</p>
  
  <p>Examples:</p>
  
  <pre><code>dict before: {}
  
  call handleElement(“ip”,”localhost”, [os, network])
  dic after: {“os”: {“network”: {“ip”: “localhost”}}
  
  call handleElement (“ip”,””, [os, network])
  dic after: {}
  
  call handleElement (“ip”,”localhost”, [os, network])
  call handleElement (“subnetmask”,”full”, [os, network])
  dic after: {“os”: {“network”: {“ip”: “localhost”, “subnetmask”:”full”}}
  
  call handleElement (“ip”,””, [os, network])
  dic after: {“os”: {“network”: { “subnetmask”:”full”}}
  </code></pre>