Python Create JSON File from List Example
Hey,
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:
main.py
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")
Output:
After run successfully above example, you will see data.json file saved in your root path and file content will be as the below:
[ "Rajkot", "Surat", "Ahmadabad", "Baroda" ]
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Read a JSON File in Python?
- How to Create a JSON File in Python?
- Python Read CSV File Specific Column Example
- How to Get Column Names from CSV File in Python?
- Python Read CSV File Line by Line Example
- Python Read CSV File Without Header Example
- Python Post Request with Basic Authentication Example
- Python Get File Extension from Filename Example
- Python Get First Date of Last Month Example
- Python Create Zip Archive from Directory Example
- How to Check if Today is Friday or not in Python?
- How to Check if Today is Tuesday or not in Python?