polars.LazyFrame.write_json#

LazyFrame.write_json(file: None = None, *, to_string: bool | None = None) str[source]#
LazyFrame.write_json(file: io.IOBase | str | pathlib.Path, *, to_string: bool | None = None) None

Write the logical plan of this LazyFrame to a file or string in JSON format.

Parameters:
file

File path to which the result should be written. If set to None (default), the output is returned as a string instead.

to_string

Deprecated argument. Ignore file argument and return a string.

Examples

>>> df = pl.DataFrame(
...     {
...         "foo": [1, 2, 3],
...         "bar": [6, 7, 8],
...     }
... ).lazy()
>>> df.write_json()
'{"DataFrameScan":{"df":{"columns":[{"name":"foo","datatype":"Int64","values":[1,2,3]},{"name":"bar","datatype":"Int64","values":[6,7,8]}]},"schema":{"inner":{"foo":"Int64","bar":"Int64"}},"output_schema":null,"projection":null,"selection":null}}'