code: def sanitize_object_to_primitives(obj):
      if isinstance(obj, dict):
          obj_sanitized = dict()
          for key, val in obj.items():
              obj_sanitized[key] = sanitize_object_to_primitives(val)
      else:
          try:
              json.dumps(obj)
              obj_sanitized = obj
          except (TypeError, OverflowError):
              json.dumps(type(obj).__name__)
              obj_sanitized = type(obj).__name__
      return obj_sanitized
  
imports: import json
  import logging
  import os
  import tempfile
  from ..utils import s3_utils
label_desc: Use image node_id 2 for calling a global function with example usage: sanitize_object_to_primitives(obj) and returns: obj_sanitized