code: def clean_empty(self, d=DEFAULT):
          
          if d is DEFAULT:
              d = self
          if isinstance(d, list):
              return [v for v in (self.clean_empty(v) for v in d) if v or v == 0]
          elif isinstance(d, type(self)):
              return type(self)({k: v for k, v in ((k, self.clean_empty(v)) for k, v in d.items()) if v or v == 0})
          elif isinstance(d, dict):
              return {k: v for k, v in ((k, self.clean_empty(v)) for k, v in d.items()) if v or v == 0}
          return d
docs: Returns a copy of d without empty leaves.
  
          https://stackoverflow.com/questions/27973988/python-how-to-remove-all-empty-fields-in-a-nested-dict/35263074