code: def json_friendly(obj):
      
      converted = True
      typename = get_full_typename(obj)
  
      if is_tf_tensor_typename(typename):
          obj = obj.eval()
      elif is_pytorch_tensor_typename(typename):
          try:
              if obj.requires_grad:
                  obj = obj.detach()
          except AttributeError:
              pass  # before 0.4 is only present on variables
  
          try:
              obj = obj.data
          except RuntimeError:
              pass  # happens for Tensors before 0.4
  
          if obj.size():
              obj = obj.numpy()
          else:
              return obj.item(), True
  
      if np and isinstance(obj, np.ndarray):
          if obj.size == 1:
              obj = obj.flatten()[0]
          elif obj.size <= 32:
              obj = obj.tolist()
      elif np and isinstance(obj, np.generic):
          obj = obj.item()
      elif isinstance(obj, bytes):
          obj = obj.decode('utf-8')
      elif isinstance(obj, (datetime, date)):
          obj = obj.isoformat()
      else:
          converted = False
      if getsizeof(obj) > VALUE_BYTES_LIMIT:
          logger.warning("Object %s is %i bytes", obj, getsizeof(obj))
  
      return obj, converted
docs: Convert an object into something that's more becoming of JSON