code: def to_dict(val):
      """Converts an object to a dict"""
      try:
          obj = ObjectEncoder().default(val)
      except TypeError:
          return val
      else:
          return obj
  
imports: from binascii import hexlify
  from collections.abc import MutableMapping
  from enum import Enum
  import itertools
  from json import JSONEncoder
  from warnings import warn
  from fiona.errors import FionaDeprecationWarning
label_desc: Use image node_id 2 for calling a global function with example usage: to_dict(val) and returns: obj, val