code: def to_json(
      cudf_val,
      path_or_buf=None,
      engine="auto",
      orient=None,
      storage_options=None,
      *args,
      **kwargs,
  ):
      """{docstring}"""
  
      if engine == "auto":
          engine = "pandas"
  
      if engine == "cudf":
          if orient not in {"records", None}:
              raise ValueError(
                  f"Only the `orient='records'` is supported for JSON writer"
                  f" with `engine='cudf'`, got {orient}"
              )
  
          if path_or_buf is None:
              path_or_buf = StringIO()
              return_as_string = True
          else:
              path_or_buf = ioutils.get_writer_filepath_or_buffer(
                  path_or_data=path_or_buf,
                  mode="w",
                  storage_options=storage_options,
              )
              return_as_string = False
  
          if ioutils.is_fsspec_open_file(path_or_buf):
              with path_or_buf as file_obj:
                  file_obj = ioutils.get_IOBase_writer(file_obj)
                  libjson.write_json(
                      cudf_val, path_or_buf=file_obj, *args, **kwargs
                  )
          else:
              libjson.write_json(
                  cudf_val, path_or_buf=path_or_buf, *args, **kwargs
              )
  
          if return_as_string:
              path_or_buf.seek(0)
              return path_or_buf.read()
      elif engine == "pandas":
          warnings.warn("Using CPU via Pandas to write JSON dataset")
          if isinstance(cudf_val, cudf.DataFrame):
              pd_data = {
                  col: maybe_return_nullable_pd_obj(series)
                  for col, series in cudf_val.items()
              }
              pd_value = pd.DataFrame(pd_data)
          else:
              pd_value = maybe_return_nullable_pd_obj(cudf_val)
          return pd.io.json.to_json(
              path_or_buf,
              pd_value,
              orient=orient,
              storage_options=storage_options,
              *args,
              **kwargs,
          )
      else:
          raise ValueError(
              f"`engine` only support {{'auto', 'cudf', 'pandas'}}, "
              f"got: {engine}"
          )
  
file_path: cudf/python/cudf/cudf/io/json.py
imports: import warnings
  from collections import abc
  from io import BytesIO, StringIO
  import numpy
  import pandas
  import cudf
  from cudf._lib import json
  from cudf.api.types import is_list_like
  from cudf.utils import ioutils
  from cudf.utils.dtypes import _maybe_convert_to_default_type
label_desc: Use image node_id 3 for calling a global function with example usage: to_json(cudf_val, path_or_buf, engine, orient, storage_options) and returns: path_or_buf, pd