How to Create JSON File from List in Python?

04-Jan-2023

.

Admin

How to Create JSON File from List in Python?

Hi Dev,

This is a short guide on how to create json file from list in python. This article will give you simple example of python create json file from list of dictionaries. This article will give you simple example of create json file from list python. I explained simply about how to create json file from list in python. Follow bellow tutorial step of python write json file from list.

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

Example :


main.py

import json

# Create List for write data into json file

data = ["Badalapur", "Vijayvada", "Rachi", "Pune"]

# 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")

Output:

[

"Badalapur",

"Vijayvada",

"Rachi",

"Pune"

]

#Python