Python Create JSON File from List Example

By Hardik Savani October 30, 2023 Category : Python


In this post, we will learn python create json file from list. This post will give you a simple example of python write json file from list. step by step explain how to create json file from list in python. you will learn create json file from list python. Let's get started with python create json file from list of dictionaries.

If you want to create a JSON file from the list in python, then I would like to help you step by step on how to write JSON file from list of dictionaries in python. python has json library to generate JSON file from list using python script. we will use open() and json dump() function to write json file.

So, let's see a simple example with output:

You can use these examples with python3 (Python 3) version.

Example 1:

import json
# Create List for write data into json file
data = ["Rajkot", "Surat", "Ahmadabad", "Baroda"]
# Create Json file with list
with open('data.json', 'w') as f:
    json.dump(data, f, indent=2)
print("New data.json file is created from list")


After run successfully above example, you will see data.json file saved in your root path and file content will be as the below:


I hope it can help you...

Tags :