code: def json_default_with_numpy(obj):
      
      if isinstance(obj, (np.integer, np.floating, np.bool_)):
          return obj.item()
      elif isinstance(obj, np.ndarray):
          return obj.tolist()
      else:
          return obj
docs: Convert numpy classes to JSON serializable objects.