How to Create JSON File from Dictionary in Python?
Hi Dev,
In this example, you will learn how to create json file from dictionary. I’m going to show you about python create json file from dictionary. This article goes in detailed on create json file from dict python. let’s discuss about how to create json file from list in python.
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.
Example :
main.py
import json
# Data to be written in dict
dictionary = {
"id" : 1,
"name" : "Piyush Patel",
"email" : "[email protected]",
"city" : "Rajkot"
}
with open("data.json", "w") as outfile:
json.dump(dictionary, outfile)
print("New data.json file is created from dict")
Output:
{"id": 1, "name": "Piyush Patel", "email": "[email protected]", "city": "Rajkot"}
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?