awswrangler.s3.to_json(df: DataFrame, path: str | None = None, index: bool = True, columns: List[str] | None = None, use_threads: bool | int = True, boto3_session: Session | None = None, s3_additional_kwargs: Dict[str, Any] | None = None, sanitize_columns: bool = False, dataset: bool = False, filename_prefix: str | None = None, partition_cols: List[str] | None = None, bucketing_info: Tuple[List[str], int] | None = None, concurrent_partitioning: bool = False, mode: str | None = None, catalog_versioning: bool = False, schema_evolution: bool = True, database: str | None = None, table: str | None = None, table_type: str | None = None, transaction_id: str | None = None, dtype: Dict[str, str] | None = None, description: str | None = None, parameters: Dict[str, str] | None = None, columns_comments: Dict[str, str] | None = None, regular_partitions: bool = True, projection_enabled: bool = False, projection_types: Dict[str, str] | None = None, projection_ranges: Dict[str, str] | None = None, projection_values: Dict[str, str] | None = None, projection_intervals: Dict[str, str] | None = None, projection_digits: Dict[str, str] | None = None, projection_formats: Dict[str, str] | None = None, projection_storage_location_template: str | None = None, catalog_id: str | None = None, **pandas_kwargs: Any) List[str] | Dict[str, List[str] | Dict[str, List[str]]]

Write JSON file on Amazon S3.


In case of use_threads=True the number of threads that will be spawned will be gotten from os.cpu_count().


Compression: The minimum acceptable version to achive it is Pandas 1.2.0 that requires Python >= 3.7.1.

  • df (pandas.DataFrame) – Pandas DataFrame

  • path (str) – Amazon S3 path (e.g. s3://bucket/filename.json).

  • index (bool) – Write row names (index).

  • columns (Optional[List[str]]) – Columns to write.

  • use_threads (bool, int) – True to enable concurrent requests, False to disable multiple threads. If enabled os.cpu_count() will be used as the max number of threads. If integer is provided, specified number is used.

  • boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 Session will be used if boto3_session receive None.

  • s3_additional_kwargs (Optional[Dict[str, Any]]) – Forwarded to botocore requests. e.g. s3_additional_kwargs={‘ServerSideEncryption’: ‘aws:kms’, ‘SSEKMSKeyId’: ‘YOUR_KMS_KEY_ARN’}

  • sanitize_columns (bool) – True to sanitize columns names or False to keep it as is. True value is forced if dataset=True.

  • dataset (bool) – If True store as a dataset instead of ordinary file(s) If True, enable all follow arguments: partition_cols, mode, database, table, description, parameters, columns_comments, concurrent_partitioning, catalog_versioning, projection_enabled, projection_types, projection_ranges, projection_values, projection_intervals, projection_digits, catalog_id, schema_evolution.

  • filename_prefix (str, optional) – If dataset=True, add a filename prefix to the output files.

  • partition_cols (List[str], optional) – List of column names that will be used to create partitions. Only takes effect if dataset=True.

  • bucketing_info (Tuple[List[str], int], optional) – Tuple consisting of the column names used for bucketing as the first element and the number of buckets as the second element. Only str, int and bool are supported as column data types for bucketing.

  • concurrent_partitioning (bool) – If True will increase the parallelism level during the partitions writing. It will decrease the writing time and increase the memory usage.

  • mode (str, optional) – append (Default), overwrite, overwrite_partitions. Only takes effect if dataset=True. For details check the related tutorial:

  • catalog_versioning (bool) – If True and mode=”overwrite”, creates an archived version of the table catalog before updating it.

  • schema_evolution (bool) – If True allows schema evolution (new or missing columns), otherwise a exception will be raised. (Only considered if dataset=True and mode in (“append”, “overwrite_partitions”)) Related tutorial:

  • database (str, optional) – Glue/Athena catalog: Database name.

  • table (str, optional) – Glue/Athena catalog: Table name.

  • table_type (str, optional) – The type of the Glue Table. Set to EXTERNAL_TABLE if None

  • transaction_id (str, optional) – The ID of the transaction when writing to a Governed Table.

  • dtype (Dict[str, str], optional) – Dictionary of columns names and Athena/Glue types to be casted. Useful when you have columns with undetermined or mixed data types. (e.g. {‘col name’: ‘bigint’, ‘col2 name’: ‘int’})

  • description (str, optional) – Glue/Athena catalog: Table description

  • parameters (Dict[str, str], optional) – Glue/Athena catalog: Key/value pairs to tag the table.

  • columns_comments (Dict[str, str], optional) – Glue/Athena catalog: Columns names and the related comments (e.g. {‘col0’: ‘Column 0.’, ‘col1’: ‘Column 1.’, ‘col2’: ‘Partition.’}).

  • regular_partitions (bool) – Create regular partitions (Non projected partitions) on Glue Catalog. Disable when you will work only with Partition Projection. Keep enabled even when working with projections is useful to keep Redshift Spectrum working with the regular partitions.

  • projection_enabled (bool) – Enable Partition Projection on Athena (

  • projection_types (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections types. Valid types: “enum”, “integer”, “date”, “injected” (e.g. {‘col_name’: ‘enum’, ‘col2_name’: ‘integer’})

  • projection_ranges (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections ranges. (e.g. {‘col_name’: ‘0,10’, ‘col2_name’: ‘-1,8675309’})

  • projection_values (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections values. (e.g. {‘col_name’: ‘A,B,Unknown’, ‘col2_name’: ‘foo,boo,bar’})

  • projection_intervals (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections intervals. (e.g. {‘col_name’: ‘1’, ‘col2_name’: ‘5’})

  • projection_digits (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections digits. (e.g. {‘col_name’: ‘1’, ‘col2_name’: ‘2’})

  • projection_formats (Optional[Dict[str, str]]) – Dictionary of partitions names and Athena projections formats. (e.g. {‘col_date’: ‘yyyy-MM-dd’, ‘col2_timestamp’: ‘yyyy-MM-dd HH:mm:ss’})

  • projection_storage_location_template (Optional[str]) – Value which is allows Athena to properly map partition values if the S3 file locations do not follow a typical …/column=value/… pattern. (e.g. s3://bucket/table_root/a=${a}/${b}/some_static_subdirectory/${c}/)

  • catalog_id (str, optional) – The ID of the Data Catalog from which to retrieve Databases. If none is provided, the AWS account ID is used by default.

  • pandas_kwargs – KEYWORD arguments forwarded to pandas.DataFrame.to_json(). You can NOT pass pandas_kwargs explicit, just add valid Pandas arguments in the function call and awswrangler will accept it. e.g. wr.s3.to_json(df, path, lines=True, date_format=’iso’)


List of written files.

Return type:



Writing JSON file

>>> import awswrangler as wr
>>> import pandas as pd
>>> wr.s3.to_json(
...     df=pd.DataFrame({'col': [1, 2, 3]}),
...     path='s3://bucket/filename.json',
... )

Writing JSON file using pandas_kwargs

>>> import awswrangler as wr
>>> import pandas as pd
>>> wr.s3.to_json(
...     df=pd.DataFrame({'col': [1, 2, 3]}),
...     path='s3://bucket/filename.json',
...     lines=True,
...     date_format='iso'
... )

Writing CSV file encrypted with a KMS key

>>> import awswrangler as wr
>>> import pandas as pd
>>> wr.s3.to_json(
...     df=pd.DataFrame({'col': [1, 2, 3]}),
...     path='s3://bucket/filename.json',
...     s3_additional_kwargs={
...         'ServerSideEncryption': 'aws:kms',
...         'SSEKMSKeyId': 'YOUR_KMS_KEY_ARN'
...     }
... )