Python Create JSON File from Dict Example
Hi Artisan,
If you need to see an example of python create json file from dict. you will learn python write json file from dictionary. you can see how to create json file from list in python. In this article, we will implement a create json file from dict python. Follow the below tutorial step of python create json file from dictionary.
If you want to create a JSON file from the dictionary in python, then I would like to help you step by step on how to write JSON file from disc 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 # Data to be written in dict dictionary = { "id" : 1, "name" : "Hardik Savani", "email" : "hardik@gmail.com", "city" : "Rajkot" } with open("data.json", "w") as outfile: json.dump(dictionary, outfile) print("New data.json file is created from dict")
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:
{"id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com", "city": "Rajkot"}
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 Write a JSON File in Python?
- 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 Without Header Example
- How to Add Header in CSV File using Python?
- How to Read Text File Line by Line in Python?
- Python Create Text File in Specific Directory Example
- Python Create an Empty Text File Example
- Python List Add Element at Beginning Example
- How to Add Multiple Elements to a List in Python?