With the pandas library, this is as easy as using two commands!

df = pd.read_json()

read_json converts a JSON string to a pandas object (either a series or dataframe). Then:

df.to_csv()

Which can either return a string or write directly to a csv-file. See the docs for to_csv.

Based on the verbosity of previous answers, we should all thank pandas for the shortcut.

For unstructured JSON see this answer.

EDIT: Someone asked for a working minimal example:

import pandas as pd

with open('jsonfile.json', encoding='utf-8') as inputfile:
    df = pd.read_json(inputfile)

df.to_csv('csvfile.csv', encoding='utf-8', index=False)
Answer from vmg on Stack Overflow
Top answer
1 of 16
280

With the pandas library, this is as easy as using two commands!

df = pd.read_json()

read_json converts a JSON string to a pandas object (either a series or dataframe). Then:

df.to_csv()

Which can either return a string or write directly to a csv-file. See the docs for to_csv.

Based on the verbosity of previous answers, we should all thank pandas for the shortcut.

For unstructured JSON see this answer.

EDIT: Someone asked for a working minimal example:

import pandas as pd

with open('jsonfile.json', encoding='utf-8') as inputfile:
    df = pd.read_json(inputfile)

df.to_csv('csvfile.csv', encoding='utf-8', index=False)
2 of 16
152

First, your JSON has nested objects, so it normally cannot be directly converted to CSV. You need to change that to something like this:

{
    "pk": 22,
    "model": "auth.permission",
    "codename": "add_logentry",
    "content_type": 8,
    "name": "Can add log entry"
},
......]

Here is my code to generate CSV from that:

import csv
import json

x = """[
    {
        "pk": 22,
        "model": "auth.permission",
        "fields": {
            "codename": "add_logentry",
            "name": "Can add log entry",
            "content_type": 8
        }
    },
    {
        "pk": 23,
        "model": "auth.permission",
        "fields": {
            "codename": "change_logentry",
            "name": "Can change log entry",
            "content_type": 8
        }
    },
    {
        "pk": 24,
        "model": "auth.permission",
        "fields": {
            "codename": "delete_logentry",
            "name": "Can delete log entry",
            "content_type": 8
        }
    }
]"""

x = json.loads(x)

f = csv.writer(open("test.csv", "wb+"))

# Write CSV Header, If you dont need that, remove this line
f.writerow(["pk", "model", "codename", "name", "content_type"])

for x in x:
    f.writerow([x["pk"],
                x["model"],
                x["fields"]["codename"],
                x["fields"]["name"],
                x["fields"]["content_type"]])

You will get output as:

pk,model,codename,name,content_type
22,auth.permission,add_logentry,Can add log entry,8
23,auth.permission,change_logentry,Can change log entry,8
24,auth.permission,delete_logentry,Can delete log entry,8
Discussions

python - How do I append JSON entries to CSV file under columns with the same names as the keys? - Stack Overflow
How do I make it so that the data is appended to the correct column on the csv file and if the file does not have a certain column, we create a new one and set values of other entries to null? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to transform a JSON file into a CSV one in Python?
Hi Everyone, I have a quick question. Thanks to a previous post : Python: Extract Data from an Interactive Map on the Web, with Several Years, into a CSV file I was been able to extract JSON data from the web. Thanks again to @FelixLeg & @kknechtel to their useful help and advices. More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
April 8, 2024
python - Append key of JSON as csv column while writing to CSV - Stack Overflow
I am new to Python, I need to convert the following JSON format to csv. { "2efbc1d": ["ad5460", 32.8963, -84.3213, 74, 39000, 596, 10048, 8444, "B737", "N958WN", 1395360005, "", "", "", 0, 0, "", ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 10, 2014
python 2.7 - append data to an existing json file - Stack Overflow
I am trying to append the csv data into the above mentioned json so it looks this, keeping the order as it is: More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 10, 2017
๐ŸŒ
Gigasheet
gigasheet.com โ€บ post โ€บ convert-json-to-csv-python
How to Convert JSON to CSV in Python
The snippet simply opens the file and using the json.loads function reads the content from the file handle. Once done, it creates a normalized data frame using the json_normalize function from the Pandas library. Hereโ€™s the output from the console after we print the jsonBody and csvBody variables: Again, these examples are fairly simple JSON objects. If youโ€™re dealing with large objects with multiple nested fields, you might come across several problems in Pythonโ€™s JSON to CSV conversion.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ convert-json-to-csv-in-python
Convert JSON to CSV in Python - GeeksforGeeks
April 8, 2025 - Explanation: This code reads a JSON file (data.json), extracts the emp_details list, and writes it into a CSV file (data_file.csv). It writes the headers (keys) from the first employee and then appends the employee details (values) as rows in the CSV.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 75066245 โ€บ how-do-i-append-json-entries-to-csv-file-under-columns-with-the-same-names-as-th
python - How do I append JSON entries to CSV file under columns with the same names as the keys? - Stack Overflow
import pandas as pd import requests response = requests.get(f'https://www.magicbricks.com/mbsrp/propertySearch.html?editSearch=Y&category=S&propertyType=10002,10003,10021,10022,10001,10017,10000&bedrooms=11700,11701,11702,11703,11704,11705,11706,11707,11708,11709,11710&city=4320&page=2&groupstart=30&offset=0&maxOffset=248&sortBy=premiumRecent&postedSince=-1&pType=10002,10003,10021,10022,10001,10017,10000&isNRI=N&multiLang=en') df = pd.json_normalize(response.json()['resultList'], max_level=0) df.to_csv('property_data.csv', mode='a') for i in range(3, 102): response = requests.get(f'https://www
๐ŸŒ
Medium
medium.com โ€บ @gabrielpires โ€บ how-to-convert-a-json-file-to-csv-python-script-a9ff0a3f906e
How to convert a JSON file to CSV โ€” PYTHON SCRIPT | by Gabriel Pires | Medium
May 6, 2020 - Create a new Python file like: json_to_csv.py ยท Add this code: import csv, json, sys #if you are not using utf-8 files, remove the next line sys.setdefaultencoding("UTF-8") #set the encode to utf8 #check if you pass the input file and output ...
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ how to convert json to csv in python
How to Convert JSON to CSV in Python โ€ข datagy
December 15, 2022 - The following steps convert a JSON string to a CSV file using Python: ... Use the df.to_csv() method to convert the DataFrame to a CSV file, by specifying the filename in the method.
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How to transform a JSON file into a CSV one in Python? - Python Help - Discussions on Python.org
April 8, 2024 - Hi Everyone, I have a quick question. Thanks to a previous post : Python: Extract Data from an Interactive Map on the Web, with Several Years, into a CSV file I was been able to extract JSON data from the web. Thanks again to @FelixLeg & @kknechtel to their useful help and advices.
๐ŸŒ
Enterprise DNA
blog.enterprisedna.co โ€บ python-convert-json-to-csv
Python: Convert JSON to CSV, Step-by-Step Guide โ€“ Master Data Skills + AI
Using pandas can be quick and easy, but itโ€™s not the only tool in the Python toolbox. Another option is to use the json2csv library, which provides a simple command-line interface for converting JSON files to CSV format. It offers flexibility in specifying the JSON keys and CSV fields.
๐ŸŒ
Verpex
verpex.com โ€บ blog โ€บ website tips โ€บ how to convert json to...
How to Convert JSON to CSV in Python
Convert JSON to CSV in Python easily. Step-by-step guide with examples using pandas and json libraries for simple and nested data.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ convert json to csv python
How to Convert JSON to CSV in Python | Delft Stack
March 11, 2025 - Finally, we use the to_csv() method to write the DataFrame to a CSV file named output.csv. The index=False parameter ensures that the index column is not included in the output file.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas โ€“ convert json to csv
Pandas - Convert JSON to CSV - Spark By {Examples}
November 1, 2024 - # Read json from String json_str = '{"Courses":{"r1":"Spark"},"Fee":{"r1":"25000"},"Duration":{"r1":"50 Days"}}' df = pd.read_json(json_str) print(df) # Output: # Courses Fee Duration # r1 Spark 25000 50 Days ยท This is an optional step. In real-time applications, we are often required to transform the data and write the DataFrame result to a CSV file.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-nested-json-to-csv-in-python
Convert nested JSON to CSV in Python - GeeksforGeeks
July 23, 2025 - The desired CSV data is created using the generate_csv_data() function. This function concatenates each record using a comma (,) and then all these individual records are appended with a new line ('\n' in python).
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-json-to-csv
How to Convert JSON to CSV in Python | LearnPython.com
Finally, we write our header data, followed by each row using the writeheader() and writerows() functions. For more information on the csv module, check out A Guide to the Python csv Module, How to Read CSV Files in Python, and Read a CSV File Into a List in Python. There is a way to achieve the same result using only one module and far fewer lines of code. It makes the process of converting JSON to CSV easier, more readable, and less error prone.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 24130613 โ€บ append-key-of-json-as-csv-column-while-writing-to-csv
python - Append key of JSON as csv column while writing to CSV - Stack Overflow
June 10, 2014 - import json import csv with open("data.json") as file: data = json.load(file) with open("data.csv", "w") as file: csv_file = csv.writer(file) print( data.keys()) newlist = list() for i in data.keys(): newlist.append(i) print(newlist[1]) cnt ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 47739646 โ€บ append-data-to-an-existing-json-file
python 2.7 - append data to an existing json file - Stack Overflow
December 10, 2017 - import csv from itertools import izip_longest # use zip_longest on Python 3.x with open("input_file.csv", "rb") as f: # open the CSV file for reading reader = csv.reader(f) # build a CSV reader header = next(reader) # lets store the header so we can get the key values later for index, row in enumerate(reader): # enumerate and iterate over the rest if index >= len(json_data): # there are more CSV rows than we have elements in JSO break row = [(header[i], v) for i, v in enumerate(row)] # turn the row into element tuples # since collections.OrderedDict doesn't support random access by index we'll
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 70325623 โ€บ store-json-data-to-json-file-and-save-them-in-the-csv-file
python - Store Json data to JSON file and save them in the CSV file - Stack Overflow
To save json data in a .csv file, ... or add additional context in comments. ... You can't append JSON files together into a new JSON, because of the nature of the JSON format....
Top answer
1 of 3
1

The solution is to add all your data into a dictionary or other data structure like a list.

After that use the csv library to write a proper CSV file.

https://docs.python.org/3/library/csv.html

Tha will look like this.

I would use ; considering you have a list of names separated by ,.

But why not write it all in a JSON file instead of a CSV.

A CSV will look like this.


name;age;married;divorced;children;pets;cars
John;30;true;false;Ann,Billy;;model,BMW 230,mpg,27.5,model,Ford Edge,mpg,24.1

....

It is preferred to store it all in a JSON, so you can keep the data schema.

Anyways you need to store your data in a dict or a list and then write it to a JSON file with json library

https://docs.python.org/3/library/json.html

The json file will look like you said.

{"name": "John", "age": 30, "married": true, "divorced": false, "children": ["Ann", "Billy"], "pets": null, "cars": [{"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1}]}
{"name": "Doe", "age": 33, "married": true, "divorced": false, "children": ["Peter", "Billy"], "pets": null, "cars": [{"model": "Tesla", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 27.1}]}
{"name": "Kurt", "age": 13, "married": true, "divorced": false, "children": ["Bruce", "Nikola"], "pets": null, "cars": [{"model": "Mercedes", "mpg": 27.5}, {"model": "123", "mpg": 24.1}]}
2 of 3
0

You can install and import pandas, then use a '.to_csv()'.

For ex.:

import pandas as pd
df = pd.read_json (r'Path where the JSON file is saved\File Name.json')
df.to_csv (r'Path where the new CSV file will be stored\New File Name.csv', index = None)

You can find the documentation here -> pandas.pydata.org

๐ŸŒ
Medium
medium.com โ€บ @harikrishnank497 โ€บ converting-json-to-csv-using-python-66c38826a751
Converting JSON to CSV Using Python | by Harikrishnan K | Medium
July 1, 2024 - import json import csv import os def convert_json_to_csv(input_json_file, output_csv_folder): # Ensure the output folder exists os.makedirs(output_csv_folder, exist_ok=True) # Determine the output CSV filename base_name = os.path.splitext(os.path.basename(input_json_file))[0] output_csv_file = os.path.join(output_csv_folder, base_name + '.csv') # Read the JSON file with open(input_json_file, 'r') as json_file: data = json.load(json_file) # Ensure the data is a list of dictionaries if not isinstance(data, list): raise ValueError("JSON data must be a list of dictionaries") # Write to the CSV fil
๐ŸŒ
Inventive HQ
inventivehq.com โ€บ home โ€บ blog โ€บ python โ€บ json to csv python converter | transform and export data with code
JSON to CSV Python Converter | Transform and Export Data with Code
November 1, 2025 - Hereโ€™s a complete Python script that converts our JSON data to CSV format: import json import csv def json_to_csv(json_file_path, csv_file_path): """ Convert a JSON file to CSV format.