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.5 documentation
Convert the object to a JSON string. Note NaN’s and None will be converted to null and datetime objects will be converted to UNIX timestamps. ... String, path object (implementing os.PathLike[str]), or file-like object implementing a write() function.
🌐
GeeksforGeeks
geeksforgeeks.org › python › exporting-pandas-dataframe-to-json-file
Exporting Pandas DataFrame to JSON File - GeeksforGeeks
DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 9 Apr, 2026 · To export a Pandas DataFrame to a JSON file we use to_json() function.
Published: April 9, 2026
🌐
W3Schools
w3schools.com › python › pandas › pandas_json.asp
Pandas Read JSON
In our examples we will be using a JSON file called 'data.json'. Open data.json. ... Tip: use to_string() to print the entire DataFrame. ... JSON objects have the same format as Python dictionaries.
🌐
Python Guides
pythonguides.com › how-to-convert-python-dataframe-to-json
Convert A DataFrame To JSON In Python (6 Methods)
May 28, 2025 - The simplest way to convert a DataFrame to JSON is by using the built-in to_json() method in Python.
🌐
Python Examples
pythonexamples.org › pandas-convert-dataframe-to-json
Pandas – Convert DataFrame to JSON
The resulting JSON String is written to the specified file path. import pandas as pd df = pd.DataFrame({'name':['a', 'b', 'c'], 'age' :[20, 21, 20]}) df.to_json(path_or_buf='output.json')
🌐
Data to Fish
datatofish.com › export-pandas-dataframe-json
How to Export a pandas DataFrame as a JSON File
import pandas as pd data = {'fish': ['salmon', 'pufferfish', 'shark'], 'count': [100, 10, 1], } df = pd.DataFrame(data) print(df) ... import os desktop_path = os.path.expanduser('~/Desktop') df.to_json(desktop_path + '/fish.json', orient='columns') After you run this, you should find a fish.json ...
Find elsewhere
🌐
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 - The to_json() method in Python's Pandas library is an efficient tool for converting DataFrame structures into JSON format. This capability is particularly valuable in data interchange scenarios where JSON is the preferred format for data ...
🌐
Medium
medium.com › @machinelearningpy123 › pandas-dataframe-to-json-8-code-examples-8f76a41599ef
Pandas DataFrame to JSON [8 Code Examples] | by Zeeshan Ali | Medium
November 19, 2023 - The to_json() method in Pandas allows us to convert a DataFrame to a JSON string. It provides various options to customize the output format. ... # Create a sample DataFrame data = {'Name': ['John', 'Jane', 'Jim'], 'Age': [30, 25, 35]} df = ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.1 › reference › api › pandas.DataFrame.to_json.html
pandas.DataFrame.to_json — pandas 2.1.4 documentation
Convert the object to a JSON string. Note NaN’s and None will be converted to null and datetime objects will be converted to UNIX timestamps. ... String, path object (implementing os.PathLike[str]), or file-like object implementing a write() function.
🌐
Python Basics
pythonbasics.org › home › pandas › json with python pandas
JSON with Python Pandas - pythonbasics.org
To do so, use the method to_json(filename). If you want to save to a json file, you can do the following: ... import pandas as pd import json data = [['Axel',32], ['Alice', 26], ['Alex', 45]] df = pd.DataFrame(data,columns=['Name','Age']) df.to_json('example.json')
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-to_json.php
Pandas DataFrame: to_json() function - w3resource
May 27, 2026 - The to_json() function is used to convert the object to a JSON string. Note: NaN's and None will be converted to null and datetime objects will be converted to UNIX timestamps. ... DataFrame.to_json(self, path_or_buf=None, orient=None, ...
🌐
Moonbooks
en.moonbooks.org › Articles › How-to-store-a-pandas-dataframe-into-a-json-file-
How to store a pandas dataframe into a json file ? - Moonbooks
import json res = df.to_json(orient="split") res_d = json.loads(res) with open('data.json', 'w') as fp: json.dump(res_d, fp) ... Earth observation scientist and developer, I explore satellite data, fire detection, and environmental analytics using Python and machine learning.
🌐
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 convert Pandas DataFrame to JSON string by using the DataFrame.to_json() method. This method takes a very important param orient which accepts
🌐
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.pandas › api › pyspark.pandas.DataFrame.to_json.html
pyspark.pandas.DataFrame.to_json — PySpark master documentation
If ‘orient’ is ‘records’ write out line delimited json format. Will throw ValueError if incorrect ‘orient’ since others are not list like. It should be always True for now. ... It should be always ‘records’ for now. compression{‘gzip’, ‘bz2’, ‘xz’, None} A string representing the compression to use in the output file, only used when the first argument is a filename.
🌐
GeeksforGeeks
geeksforgeeks.org › load-json-string-into-pandas-dataframe
Load JSON String into Pandas DataFrame | GeeksforGeeks
August 18, 2020 - Pandas a powerful Python library for data manipulation provides the to_json() function to convert a DataFrame into a JSON file and the read_json() function to read a JSON file into a DataFrame.