In this program, we will see how to write a JSON file using Python,
Program:#
# Code2care Python Programs
# How wirite JSON file
#
import json
json_str = """[
{
"name":"Mike",
"age":29,
"city":"New York"
},
{
"name":"John",
"age":21,
"city":"Chicago"
},
{
"name":"Sam",
"age":23,
"city":"London"
},
{
"name":"Brian",
"age":19,
"city":"Madrid"
},
{
"name":"Danny",
"age":27,
"city":"New York"
}
]"""
# Writing JSON to a .json file
with open("my-json-file.json", "w") as outfile:
outfile.write(json_str)
json_file = open("my-json-file.json", "r")
json_str = json_file.read()
json_obj = json.loads(json_str)
for element in json_obj:
print(element['name'])
print(element['age'])
print(element['city'])
print("-----------")

Content of JSON file
More Posts related to Python,
- How to add two float numbers in Python
- tkinter - Hello World! Program
- Convert Float to String in Python
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- How to List all Packages installed using pip [Python]
- Check if String Contains a Substring - Python
- Change label (text) color in tkinter
- Where does brew install python in macOS
- Validate email address in Python using regular expression (regex)
- How to uninstall pip Python packages
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python: Fix command not found pip or pip3 on zsh shell
- Check version of pip package installer for Python
- 3 Python program to add two numbers
- Calculate discount amount python code
- How to add borders to tkinter label text
- How to install Python 3.9 using brew on Mac
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- Comments in Python Programming
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to take user input from the console in a Python program
- Install and Run Jupyter Notebook on Mac (macOS)
- Tkinter - add x and y padding to label text
- 7 Python Arithmetic Operators with Examples [Tutorial]
- Python Sleep Function/Method Code Example
More Posts:
- Fix Power BI 404 not found error when connecting SharePoint Online List as Data Source - SharePoint
- #HappyBirthdayJimin hashtag trending on BTS Jimin 25th birthday [BTS ARMY] - BTS
- zsh: command not found: cls macOS Big Sur - MacOS
- SharePoint - Use Today's Date Time in list view filter and calculated column - SharePoint
- Drag drop files here option missing for SharePoint document library - SharePoint
- AVD Pixel_2_API_15 is already running. [Android Studio] - Android-Studio
- Use Netbeans keyboard shortcuts in Android Studio - Android-Studio
- How to shuffle lines randomly in Sublime Text - Sublime-Text