In newer versions of pandas (0.20.0+, I believe), this can be done directly:

df.to_json('temp.json', orient='records', lines=True)

Direct compression is also possible:

df.to_json('temp.json.gz', orient='records', lines=True, compression='gzip')
Answer from Brad Solomon on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.to_json.html
pandas.DataFrame.to_json — pandas 3.0.1 documentation
Handler to call if object cannot otherwise be converted to a suitable format for JSON. Should receive a single argument which is the object to convert and return a serialisable object. ... If ‘orient’ is ‘records’ write out line-delimited json format.
🌐
Skytowner
skytowner.com › explore › pandas_dataframe_to_json_method
Pandas DataFrame | to_json method with Examples
The path to where you want to save the JSON. By default, the method will return a JSON string without writing to a file. ... How you want convert the source DataFrame into a JSON. ... Here, we call each item a record. ... By default, orient="columns".
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas – convert dataframe to json string
Pandas - Convert DataFrame to JSON String - Spark By {Examples}
November 5, 2024 - You can also use orient ='values' to get DataFrame as an array of values. # Convert Pandas DataFrame to JSON # Using orient ='values' df2 = df.to_json(orient ='values') print("After converting DataFrame to JSONstring:\n", df2)
🌐
GitHub
github.com › pandas-dev › pandas › issues › 29928
Using to_json/read_json with orient='table' on a DataFrame with a single level MultiIndex does not work · Issue #29928 · pandas-dev/pandas
November 29, 2019 - js=df.to_json() pandas.read_json(js) #ok js=df.to_json(orient='table') new_df=pandas.read_json(js, orient='table') # This is a workaround that does produce sensible results
Author   larrymouse
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-pandas-dataframe-into-json-in-python
How to convert pandas DataFrame into JSON in Python? - GeeksforGeeks
June 12, 2025 - The to_json() function converts a DataFrame into a JSON string or file. Key parameters include: path_or_buf: File path or buffer. If not specified, JSON string is returned. orient: Defines JSON structure (e.g., 'records', 'index', 'columns', etc.).
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-to_json.php
Pandas DataFrame: to_json() function - w3resource
August 19, 2022 - DataFrame.to_json(self, 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=True) Parameters: Returns: None or str If path_or_buf is None, returns the resulting json format as a string.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.to_json.html
pyspark.pandas.DataFrame.to_json — PySpark 4.1.1 documentation
output JSON format is different from pandas’. It always uses orient=’records’ for its output. This behavior might have to change soon.
Find elsewhere
🌐
Plus2Net
plus2net.com › python › pandas-to_json.php
to_json to output data in Json format from DataFrame taken from MySQL Excel & CSV files with options like orient
February 5, 2019 - import pandas as pd from sqlalchemy import create_engine my_conn = create_engine("mysql+mysqldb://userid:pw@localhost/my_db") sql="SELECT * FROM student LIMIT 0,10 " df = pd.read_sql(sql,my_conn) df.to_json('student1.json',orient='records')
🌐
Spark Code Hub
sparkcodehub.com › pandas-dataframe-to-json-guide
Converting Pandas DataFrame to JSON: A Comprehensive Guide
data = { 'Name': ['Alice', 'Bob'], 'Details': [{'id': 1}, {'id': 2}], 'Hire_Date': [pd.to_datetime('2023-01-15'), pd.to_datetime('2022-06-20')] } df = pd.DataFrame(data) json_str = df.to_json(orient='records', date_format='iso') print(json_str)
🌐
GitHub
github.com › pandas-dev › pandas › issues › 50456
BUG: JSON serialization with orient split fails roundtrip with MultiIndex · Issue #50456 · pandas-dev/pandas
December 28, 2022 - >>> df = DataFrame([[1, 2], [3, 4]], ... columns=pd.MultiIndex.from_arrays([["2022", "2022"], ['JAN', 'FEB']])) >>> df 2022 JAN FEB 0 1 2 1 3 4 >>> read_json(df.to_json(orient='split'), orient='split') 2022 JAN 2022 FEB 0 1 2 1 3 4
Author   datapythonista
🌐
GitHub
github.com › pandas-dev › pandas › issues › 17566
DataFrame to_json Column -> [values] orientation and JSON able · Issue #17566 · pandas-dev/pandas
September 18, 2017 - DataFrame to_json Column -> [values] orientation and JSON able#17566 · Copy link · Labels · IO JSONread_json, to_json, json_normalizeread_json, to_json, json_normalizeUsage Question · Wall-ee · opened · on Sep 18, 2017 · Issue body actions · #7863 has mentioned that to_dict(orient='list') could be a solution.
Author   Wall-ee
🌐
datagy
datagy.io › home › pandas tutorials › pandas reading & writing data › convert a pandas dataframe to json
Convert a Pandas DataFrame to JSON • datagy
December 15, 2022 - By passing 'records' into the Pandas ... you return a JSON string that formats the data in the format of a list of dictionaries where the keys are the columns and the values are the records for each individual record...
🌐
pandas
pandas.pydata.org › pandas-docs › dev › reference › api › pandas.DataFrame.to_json.html
pandas.DataFrame.to_json — pandas 3.0.0rc1+117.gff0cd9a3a7 documentation
Handler to call if object cannot otherwise be converted to a suitable format for JSON. Should receive a single argument which is the object to convert and return a serialisable object. ... If ‘orient’ is ‘records’ write out line-delimited json format.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › to_json
Python Pandas DataFrame to_json() - Convert to JSON | Vultr Docs
December 31, 2024 - In this example, the DataFrame df is converted to a JSON string. By default, the to_json() method uses the 'columns' orientation, where each column becomes a key, and their values are listed in an array.
🌐
Saturn Cloud
saturncloud.io › blog › converting-pandas-dataframe-to-json-object-column-a-comprehensive-guide
Converting Pandas DataFrame to JSON Object Column: A Guide | Saturn Cloud Blog
January 4, 2024 - Now, we can convert the DataFrame to a JSON object. We use the to_json() function, which converts the DataFrame to a JSON string. We will also use the orient='records' parameter to create a list of records in the JSON string.