code: def public_dict(d):
      
  
      if isinstance(d, dict):
          safe_dict = dict((key, public_dict(value)) for key, value in d.items() if not key.startswith('_'))
          if '_cls' in d:
              safe_dict['type'] = d['_cls']
          return safe_dict
      if isinstance(d, list):
          return [public_dict(l) for l in d]
  
      return d
docs: if type(d) is dict:
          return dict((k, public_dict(v)) for k, v in d.items() if not k.startswith('_'))
      elif type(d) is list:
          return [public_dict(v) for v in d]
      else:
          return d