code: def to_json(
      path_or_buf,
      obj,
      orient=None,
      date_format="epoch",
      double_precision=10,
      force_ascii=True,
      date_unit="ms",
      default_handler=None,
      lines=False,
      compression="infer",
      index=True,
  ):
      if not index and orient not in ["split", "table"]:
          raise ValueError(
              "'index=False' is only valid when 'orient' is "
              "'split' or 'table'"
          )
  
      path_or_buf = _stringify_path(path_or_buf)
      if lines and orient != "records":
          raise ValueError(
              "'lines' keyword only valid when 'orient' is records"
          )
  
      if orient == "table" and isinstance(obj, Series):
          obj = obj.to_frame(name=obj.name or "values")
      if orient == "table" and isinstance(obj, DataFrame):
          writer = JSONTableWriter
      elif isinstance(obj, Series):
          writer = SeriesWriter
      elif isinstance(obj, DataFrame):
          writer = FrameWriter
      else:
          raise NotImplementedError(
              "'obj' should be a Series or a DataFrame"
          )
  
      s = writer(
          obj,
          orient=orient,
          date_format=date_format,
          double_precision=double_precision,
          ensure_ascii=force_ascii,
          date_unit=date_unit,
          default_handler=default_handler,
          index=index,
      ).write()
  
      if lines:
          s = _convert_to_line_delimits(s)
  
      if isinstance(path_or_buf, compat.string_types):
          fh, handles = _get_handle(
              path_or_buf, "w", compression=compression
          )
          try:
              fh.write(s)
          finally:
              fh.close()
      elif path_or_buf is None:
          return s
      else:
          path_or_buf.write(s)
  
imports: from itertools import islice
  import os
  import numpy
  import pandas._libs.json
  from pandas._libs.tslibs import iNaT
  from pandas.compat import StringIO, long, to_str, u
  from pandas.errors import AbstractMethodError
  from pandas.core.dtypes.common import is_period_dtype
  from pandas import DataFrame, MultiIndex, Series, compat, isna, to_datetime
  from pandas.core.reshape.concat import concat
  from pandas.io.common import BaseIterator, _get_handle, _infer_compression, _stringify_path, get_filepath_or_buffer
  from pandas.io.formats.printing import pprint_thing
  from pandas.io.parsers import _validate_integer
  from .normalize import _convert_to_line_delimits
  from .table_schema import build_table_schema, parse_table_schema
label_desc: Use image node_id 1 for calling a global function with example usage: to_json(path_or_buf, obj, orient, date_format, double_precision, force_ascii, date_unit, default_handler, lines, compression, index) and returns: s