def to_json(self, path: Optional[str]=None, compression: str='uncompressed', num_files: Optional[int]=None, mode: str='overwrite', orient: str='records', lines: bool=True, partition_cols: Optional[Union[(str, List[str])]]=None, index_col: Optional[Union[(str, List[str])]]=None, **options: Any) -> Optional[str]:
    '\n        Convert the object to a JSON string.\n\n        .. note:: pandas-on-Spark `to_json` writes files to a path or URI. Unlike pandas\',\n            pandas-on-Spark respects HDFS\'s property such as \'fs.default.name\'.\n\n        .. note:: pandas-on-Spark writes JSON files into the directory, `path`, and writes\n            multiple `part-...` files in the directory when `path` is specified.\n            This behaviour was inherited from Apache Spark. The number of files can\n            be controlled by `num_files`.\n\n        .. note:: output JSON format is different from pandas\'. It always use `orient=\'records\'`\n            for its output. This behaviour might have to change in the near future.\n\n        Note NaN\'s and None will be converted to null and datetime objects\n        will be converted to UNIX timestamps.\n\n        Parameters\n        ----------\n        path : string, optional\n            File path. If not specified, the result is returned as\n            a string.\n        lines : bool, default True\n            If ‘orient’ is ‘records’ write out line delimited json format.\n            Will throw ValueError if incorrect ‘orient’ since others are not\n            list like. It should be always True for now.\n        orient : str, default \'records\'\n             It should be always \'records\' for now.\n        compression : {\'gzip\', \'bz2\', \'xz\', None}\n            A string representing the compression to use in the output file,\n            only used when the first argument is a filename. By default, the\n            compression is inferred from the filename.\n        num_files : the number of files to be written in `path` directory when\n            this is a path.\n        mode : str {\'append\', \'overwrite\', \'ignore\', \'error\', \'errorifexists\'},\n            default \'overwrite\'. Specifies the behavior of the save operation when the\n            destination exists already.\n\n            - \'append\': Append the new data to existing data.\n            - \'overwrite\': Overwrite existing data.\n            - \'ignore\': Silently ignore this operation if data already exists.\n            - \'error\' or \'errorifexists\': Throw an exception if data already exists.\n\n        partition_cols : str or list of str, optional, default None\n            Names of partitioning columns\n        index_col: str or list of str, optional, default: None\n            Column names to be used in Spark to represent pandas-on-Spark\'s index. The index name\n            in pandas-on-Spark is ignored. By default, the index is always lost.\n        options: keyword arguments for additional options specific to PySpark.\n            It is specific to PySpark\'s JSON options to pass. Check\n            the options in PySpark\'s API documentation for `spark.write.json(...)`.\n            It has a higher priority and overwrites all other options.\n            This parameter only works when `path` is specified.\n\n        Returns\n        --------\n        str or None\n\n        Examples\n        --------\n        >>> df = ps.DataFrame([[\'a\', \'b\'], [\'c\', \'d\']],\n        ...                   columns=[\'col 1\', \'col 2\'])\n        >>> df.to_json()\n        \'[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]\'\n\n        >>> df[\'col 1\'].to_json()\n        \'[{"col 1":"a"},{"col 1":"c"}]\'\n\n        >>> df.to_json(path=r\'%s/to_json/foo.json\' % path, num_files=1)\n        >>> ps.read_json(\n        ...     path=r\'%s/to_json/foo.json\' % path\n        ... ).sort_values(by="col 1")\n          col 1 col 2\n        0     a     b\n        1     c     d\n\n        >>> df[\'col 1\'].to_json(path=r\'%s/to_json/foo.json\' % path, num_files=1, index_col="index")\n        >>> ps.read_json(\n        ...     path=r\'%s/to_json/foo.json\' % path, index_col="index"\n        ... ).sort_values(by="col 1")  # doctest: +NORMALIZE_WHITESPACE\n              col 1\n        index\n        0         a\n        1         c\n        '
    if (('options' in options) and isinstance(options.get('options'), dict) and (len(options) == 1)):
        options = options.get('options')
    if (not lines):
        raise NotImplementedError('lines=False is not implemented yet.')
    if (orient != 'records'):
        raise NotImplementedError("orient='records' is supported only for now.")
    if (path is None):
        psdf_or_ser = self
        pdf = psdf_or_ser.to_pandas()
        if isinstance(self, ps.Series):
            pdf = pdf.to_frame()
        return pdf.to_json(orient='records')
    psdf = self
    if isinstance(self, ps.Series):
        psdf = self.to_frame()
    sdf = psdf.to_spark(index_col=index_col)
    if (num_files is not None):
        sdf = sdf.repartition(num_files)
    builder = sdf.write.mode(mode)
    if (partition_cols is not None):
        builder.partitionBy(partition_cols)
    builder._set_opts(compression=compression)
    builder.options(**options).format('json').save(path)
    return None
Convert the object to a JSON string.

.. note:: pandas-on-Spark `to_json` writes files to a path or URI. Unlike pandas',
    pandas-on-Spark respects HDFS's property such as 'fs.default.name'.

.. note:: pandas-on-Spark writes JSON files into the directory, `path`, and writes
    multiple `part-...` files in the directory when `path` is specified.
    This behaviour was inherited from Apache Spark. The number of files can
    be controlled by `num_files`.

.. note:: output JSON format is different from pandas'. It always use `orient='records'`
    for its output. This behaviour might have to change in the near future.

Note NaN's and None will be converted to null and datetime objects
will be converted to UNIX timestamps.

Parameters
----------
path : string, optional
    File path. If not specified, the result is returned as
    a string.
lines : bool, default True
    If ‘orient’ is ‘records’ write out line delimited json format.
    Will throw ValueError if incorrect ‘orient’ since others are not
    list like. It should be always True for now.
orient : str, default 'records'
     It should be always 'records' for now.
compression : {'gzip', 'bz2', 'xz', None}
    A string representing the compression to use in the output file,
    only used when the first argument is a filename. By default, the
    compression is inferred from the filename.
num_files : the number of files to be written in `path` directory when
    this is a path.
mode : str {'append', 'overwrite', 'ignore', 'error', 'errorifexists'},
    default 'overwrite'. Specifies the behavior of the save operation when the
    destination exists already.

    - 'append': Append the new data to existing data.
    - 'overwrite': Overwrite existing data.
    - 'ignore': Silently ignore this operation if data already exists.
    - 'error' or 'errorifexists': Throw an exception if data already exists.

partition_cols : str or list of str, optional, default None
    Names of partitioning columns
index_col: str or list of str, optional, default: None
    Column names to be used in Spark to represent pandas-on-Spark's index. The index name
    in pandas-on-Spark is ignored. By default, the index is always lost.
options: keyword arguments for additional options specific to PySpark.
    It is specific to PySpark's JSON options to pass. Check
    the options in PySpark's API documentation for `spark.write.json(...)`.
    It has a higher priority and overwrites all other options.
    This parameter only works when `path` is specified.

Returns
--------
str or None

Examples
--------
>>> df = ps.DataFrame([['a', 'b'], ['c', 'd']],
...                   columns=['col 1', 'col 2'])
>>> df.to_json()
'[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]'

>>> df['col 1'].to_json()
'[{"col 1":"a"},{"col 1":"c"}]'

>>> df.to_json(path=r'%s/to_json/foo.json' % path, num_files=1)
>>> ps.read_json(
...     path=r'%s/to_json/foo.json' % path
... ).sort_values(by="col 1")
  col 1 col 2
0     a     b
1     c     d

>>> df['col 1'].to_json(path=r'%s/to_json/foo.json' % path, num_files=1, index_col="index")
>>> ps.read_json(
...     path=r'%s/to_json/foo.json' % path, index_col="index"
... ).sort_values(by="col 1")  # doctest: +NORMALIZE_WHITESPACE
      col 1
index
0         a
1         c
def to_json(self, path: Optional[str]=None, compression: str='uncompressed', num_files: Optional[int]=None, mode: str='overwrite', orient: str='records', lines: bool=True, partition_cols: Optional[Union[(str, List[str])]]=None, index_col: Optional[Union[(str, List[str])]]=None, **options: Any) -> Optional[str]:
    '\n        Convert the object to a JSON string.\n\n        .. note:: pandas-on-Spark `to_json` writes files to a path or URI. Unlike pandas\',\n            pandas-on-Spark respects HDFS\'s property such as \'fs.default.name\'.\n\n        .. note:: pandas-on-Spark writes JSON files into the directory, `path`, and writes\n            multiple `part-...` files in the directory when `path` is specified.\n            This behaviour was inherited from Apache Spark. The number of files can\n            be controlled by `num_files`.\n\n        .. note:: output JSON format is different from pandas\'. It always use `orient=\'records\'`\n            for its output. This behaviour might have to change in the near future.\n\n        Note NaN\'s and None will be converted to null and datetime objects\n        will be converted to UNIX timestamps.\n\n        Parameters\n        ----------\n        path : string, optional\n            File path. If not specified, the result is returned as\n            a string.\n        lines : bool, default True\n            If ‘orient’ is ‘records’ write out line delimited json format.\n            Will throw ValueError if incorrect ‘orient’ since others are not\n            list like. It should be always True for now.\n        orient : str, default \'records\'\n             It should be always \'records\' for now.\n        compression : {\'gzip\', \'bz2\', \'xz\', None}\n            A string representing the compression to use in the output file,\n            only used when the first argument is a filename. By default, the\n            compression is inferred from the filename.\n        num_files : the number of files to be written in `path` directory when\n            this is a path.\n        mode : str {\'append\', \'overwrite\', \'ignore\', \'error\', \'errorifexists\'},\n            default \'overwrite\'. Specifies the behavior of the save operation when the\n            destination exists already.\n\n            - \'append\': Append the new data to existing data.\n            - \'overwrite\': Overwrite existing data.\n            - \'ignore\': Silently ignore this operation if data already exists.\n            - \'error\' or \'errorifexists\': Throw an exception if data already exists.\n\n        partition_cols : str or list of str, optional, default None\n            Names of partitioning columns\n        index_col: str or list of str, optional, default: None\n            Column names to be used in Spark to represent pandas-on-Spark\'s index. The index name\n            in pandas-on-Spark is ignored. By default, the index is always lost.\n        options: keyword arguments for additional options specific to PySpark.\n            It is specific to PySpark\'s JSON options to pass. Check\n            the options in PySpark\'s API documentation for `spark.write.json(...)`.\n            It has a higher priority and overwrites all other options.\n            This parameter only works when `path` is specified.\n\n        Returns\n        --------\n        str or None\n\n        Examples\n        --------\n        >>> df = ps.DataFrame([[\'a\', \'b\'], [\'c\', \'d\']],\n        ...                   columns=[\'col 1\', \'col 2\'])\n        >>> df.to_json()\n        \'[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"}]\'\n\n        >>> df[\'col 1\'].to_json()\n        \'[{"col 1":"a"},{"col 1":"c"}]\'\n\n        >>> df.to_json(path=r\'%s/to_json/foo.json\' % path, num_files=1)\n        >>> ps.read_json(\n        ...     path=r\'%s/to_json/foo.json\' % path\n        ... ).sort_values(by="col 1")\n          col 1 col 2\n        0     a     b\n        1     c     d\n\n        >>> df[\'col 1\'].to_json(path=r\'%s/to_json/foo.json\' % path, num_files=1, index_col="index")\n        >>> ps.read_json(\n        ...     path=r\'%s/to_json/foo.json\' % path, index_col="index"\n        ... ).sort_values(by="col 1")  # doctest: +NORMALIZE_WHITESPACE\n              col 1\n        index\n        0         a\n        1         c\n        '
    if (('options' in options) and isinstance(options.get('options'), dict) and (len(options) == 1)):
        options = options.get('options')
    if (not lines):
        raise NotImplementedError('lines=False is not implemented yet.')
    if (orient != 'records'):
        raise NotImplementedError("orient='records' is supported only for now.")
    if (path is None):
        psdf_or_ser = self
        pdf = psdf_or_ser.to_pandas()
        if isinstance(self, ps.Series):
            pdf = pdf.to_frame()
        return pdf.to_json(orient='records')
    psdf = self
    if isinstance(self, ps.Series):
        psdf = self.to_frame()
    sdf = psdf.to_spark(index_col=index_col)
    if (num_files is not None):
        sdf = sdf.repartition(num_files)
    builder = sdf.write.mode(mode)
    if (partition_cols is not None):
        builder.partitionBy(partition_cols)
    builder._set_opts(compression=compression)
    builder.options(**options).format('json').save(path)
    return None