import json


def array_to_json(array_like):
    """
    Convert an array-like object to JSON.

    To understand what an array-like object is, please see:
    https://docs.scipy.org/doc/numpy/user/basics.creation.html#converting-python-array-like-objects-to-numpy-arrays
    Args:
        array_like (np.array or Iterable or int or float): Array-like object to be
                                                        converted to JSON.
    Returns:
        (str): Object serialized to JSON.
    """

    def default(_array_like):
        if hasattr(_array_like, "tolist"):
            return _array_like.tolist()
        return json.JSONEncoder().default(_array_like)

    return json.dumps(array_like, default=default)