pandas.Series.to_json

pandas 3.1.1 · Series and accessors · method

Serialize the object to JSON. Choose orient for the layout and lines for line-delimited records where supported.

Call syntax

Series.to_json(…) Full signature
Series.to_json(
    path_or_buf=None,
    *,
    orient=None,
    date_format=None,
    double_precision=10,
    force_ascii=True,
    date_unit='ms',
    default_handler=None,
    lines=False,
    compression='infer',
    index=None,
    indent=None,
    storage_options=None,
    mode='w',
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
path_or_buf Optional
Positional or keyword
Default None
str, path object, file-like object, or None

Supply a file path or writable/readable stream. Some writers return the result directly when this is omitted.

orient Optional
Keyword only
Default None
str

Choose how row labels, columns, and values are arranged in the serialized result.

date_format Optional
Keyword only
Default None
{None, 'epoch', 'iso'}

Specify datetime parsing or formatting directives such as "%Y-%m-%d".

double_precision Optional
Keyword only
Default 10
int
force_ascii Optional
Keyword only
Default True
bool
date_unit Optional
Keyword only
Default 'ms'
str

Choose the timestamp precision in parsed or serialized data.

default_handler Optional
Keyword only
Default None
callable
lines Optional
Keyword only
Default False
bool

Choose newline-delimited JSON records where supported.

compression Optional
Keyword only
Default 'infer'
str or dict

Choose whether and how to compress or decompress data.

index Optional
Keyword only
Default None
bool or None

Supply row labels or control how existing row labels are used.

indent Optional
Keyword only
Default None
int
storage_options Optional
Keyword only
Default None
dict

Pass storage-backend options such as connection settings or HTTP headers.

mode Optional
Keyword only
Default 'w'
str

Choose a file or storage access mode.

Returns

None or str