code: def array_to_json(ar, obj=None, force_contiguous=True):
      if ar is None:
          return None
  
      array_type = None
  
      if ar.dtype.kind == "O":
          # Try to serialize the array of objects
          is_string = np.vectorize(
              lambda x: isinstance(x, six.string_types)
          )
          is_timestamp = np.vectorize(
              lambda x: isinstance(x, pd.Timestamp)
          )
          is_array_like = np.vectorize(
              lambda x: isinstance(x, (list, np.ndarray))
          )
  
          if np.all(is_timestamp(ar)):
              ar = ar.astype("datetime64[ms]").astype(np.float64)
              array_type = "date"
          elif np.all(is_string(ar)):
              ar = ar.astype("U")
          elif np.all(is_array_like(ar)):
              return [
                  array_to_json(np.array(row), obj, force_contiguous)
                  for row in ar
              ]
          else:
              raise ValueError("Unsupported dtype object")
  
      if ar.dtype.kind in ["S", "U"]:  # strings to as plain json
          return ar.tolist()
  
      if ar.dtype.kind == "M":
          # since there is no support for int64, we'll use float64 but as ms
          # resolution, since that is the resolution the js Date object understands
          ar = ar.astype("datetime64[ms]").astype(np.float64)
          array_type = "date"
  
      if ar.dtype.kind not in [
          "u",
          "i",
          "f",
      ]:  # ints and floats, and datetime
          raise ValueError("Unsupported dtype: %s" % (ar.dtype))
  
      if ar.dtype == np.int64:  # JS does not support int64
          ar = ar.astype(np.int32)
  
      if (
          force_contiguous and not ar.flags["C_CONTIGUOUS"]
      ):  # make sure it's contiguous
          ar = np.ascontiguousarray(ar)
  
      if not ar.dtype.isnative:
          dtype = ar.dtype.newbyteorder()
          ar = ar.astype(dtype)
  
      return {
          "value": memoryview(ar),
          "dtype": str(ar.dtype),
          "shape": ar.shape,
          "type": array_type,
      }
  
imports: from traitlets import TraitError, TraitType
  import numpy
  import pandas
  import warnings
  import datetime
  import six
label_desc: Use image node_id 5 for calling a global function with example usage: array_to_json(ar, obj, force_contiguous) and returns: dict, None, ar, unknown