How to Create JSON File from List in Python?

Hi Dev,
Today, I will let you know example of python write json file from list. if you want to see example of how to create json file from list in python then you are a right place. Here you will learn python create json file from list. This post will give you simple example of create json file from list python. follow bellow step for python create json file from list of dictionaries.
So, if you want to create json file from list in python then i would like to describe python has json library to generate JSON file using python script. we will use open() and json dump() function to write json file.
So let's see bellow example:
Example
main.pyimport json # Create List for write data into json file data = ["Ahmedabad", "Mumbai", "Delhi", "Bengaluru"] # 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 running example successfully, you will see a data.json file saved in your root path, with the following content:
Output[ "Ahmedabad", "Mumbai", "Delhi", "Bengaluru" ]
It will help you....