DataFrameWriter.
json
Saves the content of the DataFrame in JSON format (JSON Lines text format or newline-delimited JSON) at the specified path.
DataFrame
New in version 1.4.0.
the path in any Hadoop supported file system
specifies the behavior of the save operation when data already exists.
append: Append contents of this DataFrame to existing data.
append
overwrite: Overwrite existing data.
overwrite
ignore: Silently ignore this operation if data already exists.
ignore
error or errorifexists (default case): Throw an exception if data already exists.
error
errorifexists
compression codec to use when saving to file. This can be one of the known case-insensitive shorten names (none, bzip2, gzip, lz4, snappy and deflate).
sets the string that indicates a date format. Custom date formats follow the formats at datetime pattern. # noqa This applies to date type. If None is set, it uses the default value, yyyy-MM-dd.
yyyy-MM-dd
sets the string that indicates a timestamp format. Custom date formats follow the formats at datetime pattern. # noqa This applies to timestamp type. If None is set, it uses the default value, yyyy-MM-dd'T'HH:mm:ss[.SSS][XXX].
yyyy-MM-dd'T'HH:mm:ss[.SSS][XXX]
specifies encoding (charset) of saved json files. If None is set, the default UTF-8 charset will be used.
set, it uses the default value, \n.
\n
Whether to ignore null fields when generating JSON objects. If None is set, it uses the default value, true.
true
Examples
>>> df.write.json(os.path.join(tempfile.mkdtemp(), 'data'))