docs: def py2json(py_obj):
      """
      Converts the inputted python object to JSON format.
      
      :param      py_obj | <variant>
      """
      method = getattr(py_obj, '__json__', None)
  
      if method:
          return method()
      elif type(py_obj) == datetime.datetime:
          return py_obj.isoformat()
      elif type(py_obj) == datetime.date:
          return py_obj.isoformat()
      elif type(py_obj) == datetime.time:
          return py_obj.isoformat()
      elif type(py_obj) == set:
          return list(py_obj)
      elif type(py_obj) == decimal.Decimal:
          return str(py_obj)
      else:
          # look through custom plugins
          for encoder in _encoders:
              success, value = encoder(py_obj)
              if success:
                  return value
  
          opts = (py_obj, type(py_obj))
          raise TypeError('Unserializable object {} of type {}'.format(*opts))